-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek_1_revision.py
More file actions
68 lines (57 loc) · 1.81 KB
/
week_1_revision.py
File metadata and controls
68 lines (57 loc) · 1.81 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
def get_student_info():
student_info = {
#Collecting User Info
"name": input("Enter student name: "),
"age": int(input("Enter student age: ")),
"grades": []
}
num_subjects = int(input("Enter the amount of subjects: "))
#Collecting grades for each subject
for i in range(num_subjects):
new_subject = input(f"Enter the name of the subject {i + 1}: ")
grade = input(f"Enter the letter grade for {new_subject}: ").upper()
#ensure valid grade input
while grade not in ["A", "B", "C", "D", "F"]:
print("Invalid grade. Please enter a grade from A, B, C, D, F.")
grade = input(f"Enter the letter grade for {new_subject}: ").upper()
student_info["grades"].append({
"subject": new_subject,
"grade": grade
})
return student_info
def total_and_average(grades, num_subjects):
grade_points = {
"A": 4,
"B": 3,
"C": 2,
"D": 1,
"F": 0
}
total = 0
for entry in grades:
letter = entry["grade"]
numerical_grade = grade_points[letter]
total += numerical_grade
average = total / num_subjects
return total, average
def display_student_summary(student_info, total, average):
print("\nStudent Information Summary:")
print("Name:", student_info["name"])
print("Age:", student_info["age"])
print("Subjects and Grades:")
for subject in student_info["grades"]:
print(f"- {subject['subject']}: {subject['grade']}")
print(f"Total Points: {total}")
print(f"Average: {average:.2f}")
def main():
while True:
student_info = get_student_info()
total, average = total_and_average(student_info["grades"], len(student_info["grades"]))
display_student_summary(student_info, total, average)
#Ask if user wants to enter another student
again = input("\nDo you want to enter another student's data? (yes/no): ").lower()
if again != "yes":
print("Goodbye!")
break
if __name__ == "__main__":
main()