-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist_dictionary.py
More file actions
160 lines (131 loc) · 4.02 KB
/
Copy pathlist_dictionary.py
File metadata and controls
160 lines (131 loc) · 4.02 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
students = []
def cal_avg(avg):
if avg >= 95:
grade = "A++"
elif avg >= 90:
grade = "A+"
elif avg >= 80:
grade = "B"
elif avg >= 70:
grade = "C"
else:
grade = "F"
if grade == "F":
print("Fail")
else:
print("Pass")
return grade
def add_student():
name = input("Enter name: ")
rollno = int(input("Enter roll no: "))
marks = []
for i in range(3):
mark = int(input(f"Enter marks for subject {i+1}: "))
marks.append(mark)
total = sum(marks)
average = total / len(marks)
grade = cal_avg(average)
student = {
"Name": name,
"Reg/no": rollno,
"Marks": marks,
"Total": total,
"Avg": average,
"Grade": grade
}
students.append(student)
print("Total: ", total)
print("Average: ", average)
print("Grade: ", grade)
def display_info():
if not students:
print("No Info to Display")
return
for student in students:
print("Name:", student["Name"])
print("Roll no:", student["Reg/no"])
print("Marks:", student["Marks"])
print("---------------------")
def highest_marks():
if not students:
print("No One to check")
return
subjects= len(students[0]["Marks"])
higher_marks= [0]*subjects
high_student= [""]*subjects
for student in students:
for i in range(subjects):
if student["Marks"][i] > higher_marks[i]:
higher_marks[i]=student["Marks"][i]
high_student[i] = student["Name"]
print("High Marks in each subject: ")
for i in range(subjects):
print(f"Subject {i+1}: {higher_marks[i]} marks by: {high_student[i]}")
def subject_average():
if not students:
print("No info present!")
return
subjects= len(students[0]["Marks"])
sub_total=[0] * subjects
for student in students:
for i in range(subjects):
sub_total[i] += student["Marks"][i]
print("Subject Wise average: ")
for i in range(subjects):
avg=sub_total[i] / len(students)
print(f"Subject {i+1}: {avg:.2f}")
def delete_student():
if not students:
print("No info to delete!")
return
rollno= int(input("Enter Roll no of student you want to delete: "))
for i in range(len(students)):
if students[i]["Reg/no"] == rollno:
remove_student = students.pop(i)
print(f"Student {remove_student['Name']} with (Reg no: {rollno}) deleted successfully!")
return
def search_student():
if not students:
print("No students!")
return
search_roll = int(input("Enter roll number to search: "))
found = False
for student in students:
if student["Reg/no"] == search_roll:
print("Student found!")
print("Name: ", student["Name"])
print("Roll no: ", student["Reg/no"])
print("Marks: ", student["Marks"])
print("Total: ", student["Total"])
print("Average: ", student["Avg"])
print("Grade: ", student["Grade"])
found= True
break
if not found:
print("Nothing to show")
while True:
print("1. Add students")
print("2. Display Students")
print("3. Display High Marks Student")
print("4. Search Student")
print("5. Subject Wise Average")
print("6. Delete Student")
print("7. Exit")
choice = input("Enter choice: ")
if choice == "1":
add_student()
elif choice == "2":
display_info()
elif choice == "3":
highest_marks()
elif choice == "4":
search_student()
elif choice == "5":
subject_average()
elif choice== "6":
delete_student()
elif choice== "7":
print("Ended!")
break
else:
print("Invalid input")