Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2a53f2c

Browse files
readme added
1 parent ab002e4 commit 2a53f2c

File tree

1 file changed

+137
-0
lines changed
  • 07_OOP_Student_performance_tracker_project

1 file changed

+137
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Student Performance Tracker
2+
3+
This Python program allows for the management and tracking of student performance through a command-line interface. It enables users to add student information, calculate averages, and determine passing status.
4+
5+
## Classes
6+
7+
### Student
8+
9+
The `Student` class represents a student with a name and their scores in various subjects.
10+
11+
#### Attributes
12+
13+
- `name`: The name of the student (string).
14+
- `scores`: A list of scores (list of integers).
15+
16+
#### Methods
17+
18+
- `__init__(self, name, scores)`: Initializes a student with a name and their scores.
19+
- `calculate_average(self) -> int`: Calculates and returns the average score of the student. Returns `0` if there are no scores.
20+
21+
- `is_passing(self, passing=40)`: Determines if the student is passing based on their average score. The default passing score is `40`.
22+
23+
```python
24+
class Student:
25+
def __init__(self,name,scores) -> None:
26+
self.name = name
27+
self.scores = scores
28+
29+
def calculate_average(self) -> int:
30+
if len(self.scores) > 0:
31+
return sum(self.scores) / len(self.scores)
32+
return 0
33+
34+
def is_passing(self,passing = 40):
35+
average = self.calculate_average()
36+
return average >= passing
37+
```
38+
39+
### Performance_tracker
40+
41+
The `Performance_tracker` class manages a collection of students and their performance.
42+
43+
#### Attributes
44+
45+
- `students_record`: A dictionary that stores student names as keys and `Student` objects as values.
46+
47+
#### Methods
48+
49+
- `__init__(self)`: Initializes an empty student record.
50+
51+
- `add_students(self)`: Prompts the user to input student names and scores. The input loop continues until the user types "stop". Updates existing student scores if the name already exists.
52+
53+
```python
54+
class Performance_tracker:
55+
def __init__(self) -> None:
56+
self.students_record = {}
57+
58+
def add_students(self):
59+
while True:
60+
try:
61+
student_name = input("\nEnter student name (or type stop to stop) : ").lower().strip()
62+
if student_name == "stop":
63+
break
64+
grades = input("Enter marks in 3 subjects (math , science and English respectively) Ensure their is space in it : ").strip()
65+
student_grades = [int(grade) for grade in grades.split()]
66+
67+
if student_name in self.students_record:
68+
self.students_record[student_name].scores = student_grades
69+
else:
70+
self.students_record[student_name] = Student(student_name,student_grades)
71+
72+
print(f"Updated dictionary : {self.get_students_data()}")
73+
74+
75+
except ValueError :
76+
print("Please enter a Valid Marks")
77+
except Exception as error :
78+
print(error)
79+
```
80+
81+
- `calculate_class_average(self)`: Calculates and prints the average score of the entire class.
82+
83+
- `display_student_performance(self)`: Displays each student's average score and passing status.
84+
85+
- `get_students_data(self)`: Returns a dictionary of student names and their scores.
86+
87+
```python
88+
def calculate_class_average(self):
89+
total_scores = []
90+
for i in self.students_record.values():
91+
total_scores.extend(i.scores)
92+
average = sum(total_scores) / len(total_scores)
93+
print(f"Class Average : {average:.2f}")
94+
95+
def display_student_performance(self):
96+
for student in self.students_record.values():
97+
average = student.calculate_average()
98+
passing = f"PASS" if student.is_passing() else "FAIL"
99+
print(f"{student.name} : Average : {average:.2f} , Status : {passing}")
100+
101+
def get_students_data(self):
102+
return {name: student.scores for name, student in self.students_record.items()}
103+
104+
```
105+
106+
## Usage
107+
108+
1. **Adding Students**:
109+
110+
- Run the program, and it will prompt you to enter student names and their scores in three subjects (math, science, and English).
111+
- Enter scores separated by spaces.
112+
- Type "stop" to finish adding students.
113+
114+
2. **Displaying Performance**:
115+
116+
- After adding students, the program will display each student's average score and their passing status (PASS/FAIL).
117+
118+
3. **Calculating Class Average**:
119+
- The program will also calculate and display the average score of the entire class.
120+
121+
## Example
122+
123+
```plaintext
124+
Enter student name (or type stop to stop) : John
125+
Enter marks in 3 subjects (math, science and English respectively): 45 55 65
126+
Updated dictionary : {'john': [45, 55, 65]}
127+
128+
Enter student name (or type stop to stop) : Jane
129+
Enter marks in 3 subjects (math, science and English respectively): 30 40 50
130+
Updated dictionary : {'john': [45, 55, 65], 'jane': [30, 40, 50]}
131+
132+
Enter student name (or type stop to stop) : stop
133+
134+
john : Average : 55.00 , Status : PASS
135+
jane : Average : 40.00 , Status : PASS
136+
Class Average : 47.50
137+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /