Week 8
Conditional Execution
Weekly Summary
How do you write programs when you need to do different things in different situations? The answer is, you use conditionals.
Recall from our prior Scratch Unit that we defined conditionals as:
This week we will begin to consider programs that use conditional statements to modify how code behaves.
Learning Outcomes
By the end of the week students should be able to:
- Reading Code
- Given a Boolean expression using one of the six Boolean operators (<, <=, >, >=, == or !=), indicate the evaluated output (True or False).
- Given a compound Boolean expression (one that includes one or more of AND, OR, or NOT, indicate the evaluated output (True or False).
- Explain the difference in Python between = and ==.
- Given a small script (including data with values) containing an if statement, indicate the output of the script.
- Given a small script containing an if/else statement, indicate the output of the script.
- Given a small script containing an if/else statement with one or more elif statements, indicate the output of the script.
- Writing Code
- Given an IPO problem statement that includes conditionals (if, if/else and if/elif/else statements), write the python code that will solve the problem.
- Debugging Code
- Given a problem statement and a non-working program that attempts to solve the problem, identify where the code is incorrect and explain how to fix it.
Learning Materials
Paired or Small-group Activity
If we were working in a face-to-face classroom I would have you complete the following POGIL activity in groups of 3 or 4 [which is the intention of POGIL activities]. Since we are not face-to-face I give you the option of either:
- completing this on your own
- completing this face-to-face with a small group of peers
- completing this online with a small group of peers
The choice is yours and you don't have to tell me (because I'm not collecting this activity. It's for learning purposes, not grading purposes).
- VIDEO - What was going on in POGIL #4 (do not watch this video until you have completed POGIL #4)
Textbook Readings
- Log on to your online textbook
- Read the following sections from your textbook
- 4.1. Boolean expressions
- NOTE: This section discusses two operators I will not expect you to use/know
- is
- is not
- NOTE: This section discusses two operators I will not expect you to use/know
- 4.2. Logical operators
- 4.3. Conditional execution
- 4.4. Alternative execution
- 4.5. Chained conditionals
- 4.6. Nested conditionals
- 4.9. Debugging
- 4.1. Boolean expressions
- Depending on where you are at in your programming journey you may find the following OPTIONAL sections helpful. Having said that, this is not material that is part of my course outcomes.
Working with Problems that use Conditionals
- VIDEO - How much should I tip?
- VIDEO - Paycheck that includes overtime
- VIDEO - Odd or Even??
- Having a vowel movement
- Can I join the Marines?
- VIDEO - Version 1, Nested Conditionals
- VIDEO - Version 1, Clean up the Spaces
- VIDEO - Version 2, Compound Conditional
Paired Programming Activity
Please complete the following Paired Programming activity with your assigned partner for the week.
Additional Explanations
Think of the following a little bit like podcasts. I will add videos here as I get questions from students or when I decide that I need to say something more beyond what is in the book. These won't "drop" on a particular day like the podcasts did in FCCS but will get added as the need arises. I would suggest you watch this space to see if new stuff has shown up. And if you have questions and feel there is a video that needs to go here PLEASE email me and let me know.
Additional Practice
The following problems are entirely optional but are provided here to give you some additional practice if you are interested. You should complete these on your own rather than with a partner.
- 4.11. Multiple Choice Questions
- 4.12. Mixed-up Code Questions
- 4.13. Write Code Questions (1-3 and 5-8)
Code Walkthroughs
The following are videos and code solutions for the programs discussed in the Paired Programming Activity. You SHOULD NOT view these until you have either solved the activities yourself - and you want to see how I would do it - or you have tried at least two different times and still are stumped. Don't jump to reading the "correct answer" too quickly. I think it is a GOOD thing to struggle with a problem for a day or two. We improve when we meet and overcome resistance. Learning comes from practice. You need to TRY before jumping to the solutions.
- Cond 1 - How old is my dog?
- Cond 2 - Is this QB having a good year?
- Cond 3 - Chinese Zodiac
- Cond 4 - Da Binz Store
Graded Practice
The following programs are formally graded as part of the Unit 2 "Problem Set." You should work on these only as an individual. While working on these problems you may refer to your notes, your textbook, any programs you wrote, and even my videos. However, you should limit your discussion of these programs with classmates. It is acceptable to discuss how you solved a problem in grand scheme of things, but you should never show your code to a classmate either as the person who is struggling or as the person who is helping a struggling classmate. You can talk ideas, but not specific solutions.
- Graded Conditionals problem set (part of the Unit 2 Problem Set).