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

POGIL Activity#4

Don't worry. You didn't miss #3. I just didn't use it in the course. [These POGIL activities are part of a set created by a different CS faculty member and used under the Creative Commons license]

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 face-to-face with a small group of peers (do you have classmates in the same building or school district?)
  • completing this online with a small group of peers (reach out to some classmates from your CoP sessions)
  • completing this on your own

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

 

  • Explanation video
    • In my classroom, we would have several opportunities to talk about what you were doing in the POGIL. Online, that gets lost.
    • You can watch this video AFTER you have completed POGIL #4 to help you debrief what happened.

 

Textbook Readings

 

Our Lessons - Working with Problems that use Conditionals

 

Practice Materials

Parsons Problems

These problems present the complete code for a program, but in a mixed-up order. Your task is to arrange the pieces correctly to "write" the described program. These problems are a great first step in learning because they allow you to focus on the semantics of programming rather than the syntax.

"Solutions" for these four programs are included in the Code Walkthrough section below.

You are welcome to complete additional problems from this section.

 

Debugging Problems

Fixing programs that are "almost" correct but not yet functional is a crucial skill. As teachers, we often assume students will develop this skill by debugging their own work. However, it can be beneficial to provide explicit practice in debugging. The following problem is designed to give you semi-guided practice in debugging.

  1. Bad code for Odd/Even produced by an AI.

The solution for this program is included in the Code Walkthrough section below.

 

(Paired) Practice Programs

Each week, I will provide you with several practice programs (non-graded) that I encourage you to attempt, with your partner, before tackling the graded assignments.

 

Additional Textbook Activities

These are great for some additional practice. You should complete these on your own rather than with a partner.

 

Code Walkthroughs

The following are videos and code solutions explaining the problems above, including the Parsons Problems, Debugging Problems, and (Paired) Programming Activity. You SHOULD NOT view these until you have either solved the activities yourself and want to see how I would do it, or you have tried at least twice and are still stumped.

Don’t jump to the "correct answer" too quickly. It’s beneficial to struggle with a problem for a day or two. We improve when we meet and overcome resistance. Learning comes from practice, so make sure to TRY before jumping to the solutions.

 

Graded Materials

The following programs are formally graded as part of the Unit 2 “Problem Set.” You should work on these individually. While working on these problems, you may refer to your notes, textbook, any programs you wrote, and my videos. However, you should significantly restrict your discussions with classmates. It is moderately acceptable to discuss how you solved a problem in general terms, but you should never show your code to a classmate, whether you are the one struggling or the one helping. You can talk about ideas, but not specific solutions.

Don't forget about the concept of Rubber Duck Debugging. If you are getting stuck this week you should absolutely pull out your rubber duck and talk to it. YES, you will feel foolish at first. But, again, the research shows that by talking out loud you can often (not always, but often) figure things out on your own. TRY IT!