Trace The Code
Loop Logic
If/Else Reasoning
Debug The Idea
Vocabulary & Concepts
100

number = 25

if number >= 26:

    print(“Large”)

elif number < 25:

    print(“Small”)

else:

    print(“Medium”)

Predict the output of this code!

What is "Medium"?

Since the given variable is 25, it is less than and not equal to 26, but also is greater than 25 so it won’t be labelled as “Small”. It goes to the “else” instead.

100

for i in range(1,7):

    print(i)


When will the code stop printing numbers?

What is "6"?


The reason why the code stopped printing right before 7 is because 7 is not included in the range and serves as a “stop sign”. This tells the code to stop printing right before 7. The last integer became 6.

100

number = 5


If number == 10:

    print(“Big”)

else:

    print(“Small”)


Why does this code come out as small instead of big?

What does it mean to fail a requirement?


The number 5 did not meet the requirements for the if statement, so it went to the else instead.

100

temp = input("Temp: ")


if temp > 0 or temp < 100: 

    print("Extreme")

elif temp >= 32:  

    print("Warm")

else

    print("Cold") 

What is wrong in this code? (Only label one error)

1.What is a logical mistake in the first if statement?

2.What is the conditional logic error in the "Warm" part?

3.What is the syntax error aka missing colon in the else?

For 1. Any value of temp would always pass the first condition so, the logic is broken. For 2. It should check for less than or equal to 32. For 3. If there is a missing colon in the else, the code will not run.

100

An if/elif/else statement takes into account ___

Fill in the blank (it's ok if your answer is a little different)

What is “A user’s input or a comparison of a variable and creates different outputs”?

Explanation: In Python, an if/elif/else statement takes in a variable’s value and compares it to meet a certain requirement. If it is met, the following output will occur. For user input, a user must input information. That information is then compared to a certain requirement. If that is met, the following output will occur.

200

for i in range(5,0,-1):

    print(i, “more times”)

print(“Done”)

What output does this code make!

What is "5 more times

4 more times

3 more times

2 more times

1 more times

Done"?

This code made a loop that counts down from 5 to 1 and added the words “more times” along with the countdown. An extra “print” was put to make “Done”.

200

for i in range(50,0,-2):

    print(i)


Does this code print even integers or odd integers and why?

What is an even integer?


The third number in the range determines how it counts down. Since it was -2, the code kept subtracting 2 from “i” every line the code ran.

200

num = int(input(“Input a number”)


if num >= 25:

    print(“Big”)

elif num < 25 and num > 10:

    print(“Medium”)

else:

    print(“Small”)

What happens if you input -5?

What is "Small"?


Negative numbers were smaller than 25 and smaller than 10. This made it go towards the else and printed small.

200

temperature = int(input("Enter temperature: "))

weather = input("Enter weather conditions (rainy/clear): ")


if temperature > 70 and weather == "clear":

    print("Perfect day!")

else:

print("Not a perfect day!")

What are the errors in this code? (Label both of them)

1. What is an indentation error in the last print?

2. What is a logic error in the if statement?

For 1. The lack of indentation in the last print causes an indentation error. The code won't run.

For 2. If someone were to say "Clear" instead of "clear" it goes to the else statement. This doesn't interrupt the code, but it may be a little annoying.

200

The difference between a string, integer, and a float is _______

Fill in the blank. (It's ok if your answer is a little different)

A string is text. An integer is a whole number. A float is a decimal number (Ex: 3.14..).

Explanation: In Python, there are three different types of data. Strings, integers, and floats. Strings are text based while integers are whole numbers. A float however is a decimal number. You cannot check if a string is equal to a number or float and vice versa.

300

total = 0

for i in range(1,6):

    total += i

print(total)

What does this code output?

What is "15"?

This code used a loop and then used “+=” which adds all integers in between the numbers in the range 1,2,3,4, and 5. When these numbers were added they made 15.

300

total = 0


for i in range(50,0,-1):

    total += i


print(total)


What does “+=” make the code do?

What is the addition of all integers in a variable?


“+=” adds all integers in a range. This can be used in loops etc.

300

food = input(“What food do you want?”)


if food == “Burger” or food == “burger”:

    size = input(“What size do you want?: ”)

    if size == “Large” or size == “large”:

        print(“$5.00”)

    elif size == “Medium” or size == “medium”:

        print(“$3.50”)

    else: 

        print(“$2.50”)

elif food == “Pizza” or food == “pizza”:

    flavor = input(“What type of pizza would you like?: “)

    if flavor == “Cheese” or flavor == “cheese”:

        print(“$2.50”)

    elif flavor == “Pepperoni” or flavor == “pepperoni”:

        print(“$3.00”)

    else:

        print(“Unavailable”)

else:

    print(“Food Unavailable”)

What happens if you say “burger” and “medium”?

What is the number 3.50?


After you input “burger” you go to the burger’s if and get asked for its size. The price changes for each size. If you input medium, you get $3.50.

300

score = int(input("Enter your test score: "))


if score < 70:

    print("Great job!")

elif score >= 70 and score <= 90:

  print("Needs improvement.")

else:

    print("Good effort.")

What are the three errors in this code? (They are all logic errors)


1. "Good Job!" is given to scores which are less than 70 which is a reverse of intended logic.

2. "Needs improvement." is given to scores between 70 and 90 which also a reverse of intended logic.

3. "Good Effort" is given to scores above 90 which is.. also a reverse of intended logic.

300

How can you control what a for loop outputs?

You can use an if/elif/else statement to control “the flow” of a for loop. For example, if you were to give the variable “i” the values 1, 2, 3, 4, and 5, and then make an if statement to print “Big” if it was larger than 3 and print "Small" if it was not, you would end up with an answer in this order; “Small” “Small” “Small” “Big” “Big”.

M
e
n
u