3. Conditionals

  • Feel free to use your laptop if you have it

  • Ensure I have recorded your completion — failure to do so will result in a grade of 0

  • I strongly encourage you to work with others in the lab

    • When you get stuck, do me a favour and ask those sitting around you for help

    • I want people to get used to working together in the labs

    • Peer teaching and peer learning is super effective


To obtain full marks for the lab, you must:

  1. Have completed the pre-lab exercises

  2. Have been working on the lab content

  3. Demonstrate competency in the topics

3.1. Pre Lab Exercises


You must have completed the specified exercises prior to the start of the lab. If you have not come to lab prepared, you will be asked to leave and you will obtain a grade of 0 for the lab.

  1. Chapter 5 exercise(s)

    • 1

    • 2 (do not forget about %)

    • 10

    • 11

3.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 some code to take input from the user and store the inputted value in a variable

    • The inputted value will be a float representing some grade between \(0 -- 100\)

  3. Call the function did_pass with the inputted value from the previous question as the argument for the function

  4. 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

  5. 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

3.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


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


Ensure that your your completion has been recorded. Failure to do so may result in a grade of 0.