Unit 2. Developing Programming Tools
Revision Date: Jul 27, 2017 (Version 2.1.1)Summary
Students will learn how programs can solve problems using the various types of conditional statements in Python programs.
Outcomes
Overview
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:
Reference Texts:
Online interpreters:
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
else:
open black box
Activity Directions:
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?
x=35
y=52
if x!=25 and y==52:
print ('Pizza is yummy')
else:
('My teacher is awesome')
Suggested Coding Example:
n = input('Please enter your password: ')
if n=='P@s5w0d':
print ('Welcome, correct user!')
else:
print ('Incorrect, try again')
Give the students the practice problem from Independent Activity 1 below. Have the students answer the following questions:
food
variable 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:
pizza
popcorn
potato salad
Thinking about conditional execution, answer the following questions.
Alternate Instructional Strategy for Guided Practice :
Alternate Instructional Strategy for Journal: Interactive Journaling