-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrade.py
More file actions
36 lines (30 loc) · 772 Bytes
/
grade.py
File metadata and controls
36 lines (30 loc) · 772 Bytes
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
from generals import is_valid_number
def main():
score = input("Enter your score: ")
# Combine validation checks
if not (is_valid_number(score) and is_valid_score(score)):
print("Invalid score")
return
score = float(score)
grade = get_grade(score)
print(f"Grade: {grade}")
def is_valid_score(score):
try:
score = float(score)
return 0 <= score <= 100
except ValueError:
return False
def get_grade(score):
"""Returns the letter grade for a given score"""
if score >= 90:
return "A"
elif score >= 80:
return "B"
elif score >= 70:
return "C"
elif score >= 60:
return "D"
else:
return "F"
if __name__ == "__main__":
main()