Unit 2. Developing Programming ToolsRevision Date: Jul 27, 2017 (Version 2.1.1)
Students will learn how programs can solve problems using the various types of conditional statements in Python programs.
Decisions in programs are made using conditional statements.
How are comparison operators and Boolean expressions used with conditional statements?
Student computer usage for this lesson is: required
In the Lesson Resources folder:
Think of a decision you make in your daily life and how you make the decision. In your journal, write about your decision and the process you use to decide.
Teaching note: take a few minutes to have students share responses (whole class, elbow partners, small groups).
==, !=, <, >, >=, <=
Includes AND, OR, and NOT
Example: Type various combinations of Boolean values (True / False) with Boolean operators (not, and, or) into the IDE (PyCharm)
Suggested Activity: What’s in the box?
Materials: Two small opaque containers, one small item for each container, two post-it notes.
Set-Up Directions: Set up the activity before the class arrives, following the directions below:
if numofGreen > numofBlack:open green box
open black box
Show the example from How to Think Like a Computer Scientist text (ActiveCode:6 (ch05_4)) or similar example. Briefly demonstrate how to read flowcharts while showing the example from How to Think Like a Computer Scientist. Point out that the API (https://docs.python.org/3/library/) is always available as a language reference to help translate from algorithms/flowcharts into code. The API describes many tools to make it easier to create programs, and is an important tool for all programmers.
Check for understanding: Have students answer to the following questions:
1. What will be printed by the following code segment?
x=15 if x==25: print ('Pizza is yummy') else: print ('My teacher is awesome')
2. What will be printed by the following code segment?
if x!=25 and y==52:
print ('Pizza is yummy')
('My teacher is awesome')
Suggested Coding Example:
n = input('Please enter your password: ')if n=='P@s5w0d':
print ('Welcome, correct user!')
print ('Incorrect, try again')
Give the students the practice problem from Independent Activity 1 below. Have the students answer the following questions:
foodvariable contains the following values?
If/else practice problem: In the IDE, write a program that will prompt a user to enter a value for a food item. Evaluate the variable
food. If the value of
food is equal to “potato salad,” display “In Stock”. If the value of
food is not equal to “potato salad,” display “Not in Stock”.
Test your program with the following values for food:
Thinking about conditional execution, answer the following questions.
Alternate Instructional Strategy for Guided Practice :
Alternate Instructional Strategy for Journal: Interactive Journaling