Loops in Action
Debug That!
Output Prediction
Syntax or Sin?
Name That Function
100

What does this code output?

for i in range(3):

    print(i)


0 1 2

100

What type of error is caused by a missing a colon in an if statement?

Syntax Error

100

What will this print?

x = 3

if x > 2:

    print("Hi")


Hi

100

Which symbol is used to start a block in Python?

Colon (:)

100

What does the print() function do?

Displays output to the screen

200

Which type of loop would you use if you don't know how many times you'll need to loop?

while loop

200

What does this code do wrong?

x = 0

while x < 5:

    print(x)

Infinite loop (x is never incremented)

200

What is printed?

x = 10

while x > 7:

    print(x)

    x -= 1


10 9 8

200

Which of these is NOT a valid syntax?

A. if x == 3
B. for i in range(5):
C. while True

A. if x == 3 (missing colon)

200

What does input() do?

Reads user input as a string

300

Write a loop that prints all even numbers from 2 to 10.

for i in range (2, 11, 2): print(i)

(prints from 2 up to but not including 11, increment by 2)

300

What built-in Python tool helps you understand where your code crashed?

Traceback

300

What will this print?

for i in range(1, 4):

    for j in range(1, 3):

        print(i * j)


1 2 2 4 3 6

300

True or False: Indentation doesn't matter in Python.

False

300

What built-in function gives the length of a list?

len()

400

What keyword can you use to exit a loop early?

break

400

Fix the bug:

for i in range(5)

    print(i)


Missing colon after range(5)

400

What is the final value of x?

x = 0

for i in range(3):

    x += i

3

400

How do you begin a comment in Python?

#

400

What does range(5) produce?

A sequence of numbers from 0 to 4
500

How many times does this loop run?

for i in range(2, 10, 2):

    print(i)

4

500

What's a good first step when you see an error?

Read the traceback and check the line it points to

500

What will this print?

for i in range(5):

    if i == 2:

        continue

    print(i)

0 1 3 4

500

What's wrong with this code?

x = input("Enter:")

print x

Missing parentheses in print (Python 3 syntax)

500

What does int() do when used with input?

Converts the string input to an integer