Trace the Code
Loop Logic
If/Else Statements
Debug the Idea
Vocabulary/Concepts
100

The word “Different” is printed this many times in the code below:


for i in range(1,6):

    if i == 3:

        print("Different")

    else:

        print(i)

1 time

(As 3 is the only one that has to be printed as “Different”, “Different” is only printed 1 time.)

100

"Hello!" will be printed this many times:

for i in range(1,6):

    print("Hello!")

5 times

("Hello!" repeats 5 times as the code allows the word to print from the set numbers 1-5.)

100

The syntax used is:

temp = int(input("What's the temp outside?: "))

if temp < 65:

    print("Cold")

else:

    print("Warm")

"if" is the syntax used.

(The syntax is what tells a computer what to do, so the "if" statement tells the computer what to do.)

100

Debug the code:


age = input("Enter age: ")


if age >= 62:

    print("You can earn your pension!")

else:

    print("Okay.")

An integer conversion is missing on line 1.

(Without the integer conversion on line 1, the “>=” cannot support the string.)

100

The name for a command that tells the computer what to do in case the if/else statements cannot cover the input.

Elif

200

Fill in the blanks to make the code make sense:


for i in [?](1,11):

    if i % 2 == [?]:

        [?](i)

“range”, "if", and “print”

(The three missing parts of the code were “range”, “if”, and “print” for the code to print the output numbers.)

200

The numbers that are the output of the code would be:

for i in range(5,51,5):

    print(i)

5, 10, 15, 20, 25, 30, 35, 40, 45, 50

(The loop starts at 5, ends at 50, and counts by 5.)

200

The amount of elifs in the code is:

temp = int(input("Temperature: "))


if temp > 80:

    print("Hot")

elif temp > 70:

    print("Warm")

elif temp > 60:

    print("Cool")

elif temp > 50:

    print("Cold")

else:

    print("Freezing")

3 elifs

(Elifs are a command that tells the computer what to do in case the if/else statements cannot cover the input.)

200

Debug the code:



time = input("What time is it?: ")

if time == Morning:

    print("Time for breakfast!")

else:

    print("Alright!"



Quotation marks are missing on line 3, and a missing parenthesis on line 6.

(The code breaks into a syntax error with the missing quotation marks and parenthesis.)

200

Putting if/else statements inside of if/else statements would be an example of a:

Nested if/else statement

300

The code prints out these certain numbers:


for i in range(1,21):

    if i % 3 == 0 and i > 10:

        print(i)

12, 15, and 18

(As 12, 15, and 18 are the only numbers that are divisible by 3 and are greater than 10 in the range 1-20, they make the most sense.)

300

The output of the code is:

total = 0

for i in range(1,6):

    total += i

print(total)

15

(0+1 = 1; 1+2 = 3; 3+3 = 6; 6+4 = 10; 10+5 = 15)

300

The outcome if you are at school but late by 50 minutes:


late = int(input("How many mins late were you?: "))


if late >= 40:

    print("Missing from class")

elif late >= 10:

    print("Why are you late")

elif late < 10:

    print("Welcome to class")


You would be missing from the class.

(Based on the placement of the code and the amount of mins you would have to be late, being missing makes sense in the code.)

300

sport = ("What's your favorite sport?: ")


if sport == ("Golf":

    print("Cool!"

if sport == "Hockey":

    print("Rough sport!")

else:

    print("Eh.")

Missing an input conversion on line 1, an missing integer conversion line 4, and line 5 should be an elif statement. 

(Without the missing parts of the code, the code ends up in a syntax error.)

300

When the rules of the programming language are being broken, what appears is a:

Syntax error