LESSON: CONDITIONAL STATEMENTS & CONTROL FLOW
WARM-UP
response = 'Y'
String - a data type that can contain letters, numbers, and symbols. answer = "Left"
if answer == "Left"
Comparators - compares two values using >, < , <= ,>=, ==. For
print "The answer is Left"
example, 5 > 6. Note: that == compares whether two things are equal,
print "Thank You"
and = assigns a value to a variable.
PROGRAMMING EXERCISES
(Requires IDLE 2.7.10)
Boolean Operators - compare statements and result in boolean
values. There are three boolean operators: and, or, not.
#1: Twinkies!
Create an if statement that checks whether a number of Twinkies (in the variable
Conditional Statement - executes some specified code after
twinkies) is less than 100 or greater than 500. Your program should print the message
checking if its expression is True. If this expression is true, run this
indented code block; otherwise, run this code after the else statement. Too few or too many if the condition is true.
VOCABULARY
Module - is a way of providing useful code to be used by another
program. The module can contain functions we can use.
PROGRAMMING CHALLENGE # 1
(Prerequisite: Completed PygLatin Module)
Mad Libs
In this activity you will program a classic game called 'Mad Libs' where
users will input parts of speech and create their own story!
Hint: It will require using the raw_input() function to receive input from
the user and string formating syntax, %s.
#2: Just the Right Number
Create an if statement that checks whether the amount of money contained in the
variable money is between 100 and 500 or between 1,000 and 5,000.
#3: I Can Fight those Ninjas
Create an if statement that prints the string Thats too many if the variable ninjas
contains a number thats less than 50, prints Itll be a struggle, but I can take em if
its less than 30, and prints I can fight those ninjas! if its less than 10. You might try
out your code with:
ninjas = 5