Reading: If Statements
Pre Class Reading Assignment
On the O'Reilly's website read chapter 5 in Python Crash Course, 3rd Edition. Here is a direct link to the readings: PCC Chapter 5: if Statements.
Remember that you will have to sign in to your free account that you created earlier.
Optional: In class we will be going over how to create different forms in Colab. Introduction to forms and different inputs.
Things to look out for
- The structure of an if statement, including the use of colons and indentation.
- How do you check if a value is or isn't in a list?
- Indentation of if and elif statements.
- What is a boolean expression?
- The difference between if, elif, and else statements.
- Can you use multiple elif statements in a single if statement?
- Note the different types of comparative operators such as >, <, and ==.
Pre-Class Quiz Challenge
-
Create a new Colab notebook.
-
Title the notebook "(Your_Name)_Pre_If_Statements.ipynb".
-
In the Colab notebook, create a variable called 'exam_score' and set it equal to an integer between 0 and 100.
-
In a new code block, use an if statement to check that the user's grade is greater than or equal to 60. Print a message telling the user whether they pass or fail.
-
In a new code block, use if, elif, and else statements to assign a letter grade based on the value of 'exam_score' using the following scale:
| Letter Grade | Grade Scale |
|---|---|
| A | 90-100 |
| B | 80-89 |
| C | 70-79 |
| D | 60-69 |
| F | Below 60 |
- Create a print statement that tells the user what their letter grade is. Great job!
Turning in/Rubric
REMINDER - For this class, you will only turn in the links to your colab notebooks. You will get a 0 for this assignment if you turn in a python file or a link that is not correct, wrong assignment, or does not give editor permission.
Rubric:
| Item | Points Possible |
|---|---|
Total |
3 |
The following is not a part of the rubric, but specifies how you can lose points. For example: if you fail to share your link correctly.
| Reasons for Points Lost | Amount |
|---|---|
| Link shared incorrectly | -10% |