-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex4.3.py
More file actions
35 lines (33 loc) · 856 Bytes
/
ex4.3.py
File metadata and controls
35 lines (33 loc) · 856 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
https://books.trinket.io/pfe/04-functions.html
'''Exercise 7: Rewrite the grade program from the previous chapter using a function called computegrade
that takes a score as its parameter and returns a grade as a string.
>= 0.9 A
>= 0.8 B
>= 0.7 C
>= 0.6 D
< 0.6 F
~~~
'''
score = input("Enter the score between 0.0 and 1.0:")
#try and catch block to ensure user enters only digits/numbers
try:
score = float(score)
except:
print("please enter a number between 0.0 and 1.0")
quit()
#initial check to see is not out of range
def computegrade(score):
if score < 0.0 or score > 1.0:
return("The entered score is out of range,")
quit()
if score >= 0.9:
return("A")
elif score >= 0.8:
return("B")
elif score >= 0.7:
return("C")
elif score >= 0.6:
return("D")
elif score < 0.6:
return("F")
print(computegrade(score))