4. Conditionals
Feel free to use your laptop
You are strongly encourage to work with others
When you get stuck, ask those sitting around you for help
Get used to working together in the labs
Peer teaching and peer learning has been empirically shown to be very effective
4.1. Pre Lab Exercises
-
1
10
11
Write assertion tests for each of your functions above
4.2. Before Kattis
Write a function
did_pass(grade: float) -> bool:
that returnsTrue
if the grade is 50 or above, andFalse
otherwiseBe sure to write some
assert
tests to verify correctness
Write a function called
letter_grade(percent_grade: float) -> str:
that takes a grade as a percentage and returns the appropriate letter grade0 - 49 -> F, 50 - 59 -> D, 60 - 69 -> C, 70 - 79 -> B, 80 - 89 -> A, 90 - 100 -> A+
Write
assert
tests to verify correctness
Rewrite
letter_grade(percent_grade: float) -> str:
such that you reverse the order you check the grade inFor example, if you checked
if grade < 50:
first, start with checking for an A+Run the
assert
tests from the previous question
4.3. Kattis Problems
Do not forget the code we used last time to read input on Kattis
1data = input() # Read a WHOLE, SINGLE line of input
2data = data.split() # Split string into individual pieces
3a_var = int(data[0]) # Take string from data[X], convert it to int...
4b_var = int(data[1]) # ... And store it in some variable
Warning
The above code will only work when the input is 2 integers on the same line. You may need to hack this code to make it work for your particular problem.