ch05
> exercises
boolean_functions.py
boolean_functions.py
Boolean functions encapsulate complex boolean logic into a single function call in order to have one place to change if the boolean logic changes.
Write a function, def percentage_to_letter(score=0)
, that when given an exam percentage (float
) as a parameter, returns a string according to this scheme:
>= 90 A
90 >= 80 B
80 >= 70 C
70 >= 60 D
< 60 F
Write a second function, def is_passing(letter=None)
, that takes a letter (single character string) and returns True
if it is a passing grade ("C"
or Better) otherwise False
.
Write a main function to test your functions. All of the below should happen in your main function:
percentage_to_letter
with the user input value as a parameterpercentage_to_letter
in a variablepercentage_to_letter
as the parameter to is_passing
is_passing
Don't forget to call your main function last in global scope:
...
# all your other code goes above this call
main()
You should have nothing other than imports, function definitions, and the call to
main()
in global scope