-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStudent_Grade_Calculator.py
More file actions
92 lines (76 loc) · 1.94 KB
/
Student_Grade_Calculator.py
File metadata and controls
92 lines (76 loc) · 1.94 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
def calculate_grade(marks):
if marks >= 90 and marks <= 100:
return 'A+'
elif marks >= 80:
return 'A'
elif marks >= 70:
return 'B+'
elif marks >= 60:
return 'B'
elif marks >= 50:
return 'C'
elif marks >= 40:
return 'D'
elif marks >= 0:
return 'F'
else:
return None # Invalid marks
def main():
print("Student Grade Calculator")
while True:
try:
marks = float(input("Enter the marks (0-100): "))
if marks < 0 or marks > 100:
print("Error: Marks should be between 0 and 100.")
continue
break
except ValueError:
print("Error: Please enter a valid number.")
continue
grade = calculate_grade(marks)
if grade:
print(f"Marks: {marks}")
print(f"Grade: {grade}")
else:
print("Invalid marks entered.")
while True:
try:
again = input("Do you want to calculate another grade? (y/n): ").strip().lower()
if again == 'y':
main() # Recursive call to restart
return
elif again == 'n':
print("Thank you for using the Student Grade Calculator!")
return
else:
print("Please enter 'y' for yes or 'n' for no.")
continue
except KeyboardInterrupt:
print("\nExiting...")
return
if __name__ == "__main__":
main()
# Student_Grade_Calculator.py
# A simple program to calculate student grades based on marks
'''
How It Works
The user inputs marks between 0 and 100.
The program checks the range and assigns a grade based on the marks.
Grades are assigned as follows:
Marks Range
Grade
90 - 100
A+
80 - 89
A
70 - 79
B+
60 - 69
B
50 - 59
C
40 - 49
D
0 - 39
F
'''