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. Chapter 5 exercise(s)

    • 1

    • 10

    • 11

  2. Write assertion tests for each of your functions above

4.2. Before Kattis

  1. Write a function did_pass(grade: float) -> bool: that returns True if the grade is 50 or above, and False otherwise

    • Be sure to write some assert tests to verify correctness

  2. Write a function called letter_grade(percent_grade: float) -> str: that takes a grade as a percentage and returns the appropriate letter grade

    • 0 - 49 -> F, 50 - 59 -> D, 60 - 69 -> C, 70 - 79 -> B, 80 - 89 -> A, 90 - 100 -> A+

    • Write assert tests to verify correctness

  3. Rewrite letter_grade(percent_grade: float) -> str: such that you reverse the order you check the grade in

    • For 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.

  1. https://open.kattis.com/problems/quadrant

  2. https://open.kattis.com/problems/judgingmoose

  3. https://open.kattis.com/problems/twostones

  4. https://open.kattis.com/problems/spavanac

  5. https://open.kattis.com/problems/cetvrta

  6. https://open.kattis.com/problems/bus