-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython project
More file actions
69 lines (59 loc) · 1.8 KB
/
Copy pathpython project
File metadata and controls
69 lines (59 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import matplotlib.pyplot as plt
# Function to calculate grade based on average
def calculate_grade(average):
if average >= 90:
return "A+"
elif average >= 80:
return "A"
elif average >= 70:
return "B"
elif average >= 60:
return "C"
elif average >= 50:
return "D"
else:
return "F"
# Collect student data
students = {}
num_students = int(input("Enter number of students: "))
for i in range(num_students):
name = input(f"\nEnter name of student {i+1}: ")
marks = []
num_subjects = int(input(f"Enter number of subjects for {name}: "))
for j in range(num_subjects):
subject = input(f" Enter subject {j+1} name: ")
mark = float(input(f" Enter marks for {subject}: "))
marks.append((subject, mark))
total = sum(m[1] for m in marks)
average = total / num_subjects
grade = calculate_grade(average)
students[name] = {
"marks": marks,
"total": total,
"average": average,
"grade": grade
}
# Display student results
print("\n--- Student Results ---")
for name, data in students.items():
print(f"\n{name}")
print(f"Total Marks: {data['total']}")
print(f"Average: {data['average']:.2f}")
print(f"Grade: {data['grade']}")
# Visualization
for name, data in students.items():
subjects = [s[0] for s in data['marks']]
marks = [s[1] for s in data['marks']]
# Bar chart
plt.figure(figsize=(6,4))
plt.bar(subjects, marks, color='skyblue')
plt.title(f"{name}'s Marks")
plt.xlabel("Subjects")
plt.ylabel("Marks")
plt.ylim(0, 100)
plt.show()
# Pie chart
plt.figure(figsize=(6,6))
plt.pie(marks, labels=subjects, autopct='%1.1f%%', startangle=140)
plt.title(f"{name}'s Marks Distribution")
plt.show()