What does this code output?
for i in range(3):
print(i)
0 1 2
What type of error is caused by a missing a colon in an if statement?
Syntax Error
What will this print?
x = 3
if x > 2:
print("Hi")
Hi
Which symbol is used to start a block in Python?
Colon (:)
What does the print() function do?
Displays output to the screen
Which type of loop would you use if you don't know how many times you'll need to loop?
while loop
What does this code do wrong?
x = 0
while x < 5:
print(x)
Infinite loop (x is never incremented)
What is printed?
x = 10
while x > 7:
print(x)
x -= 1
10 9 8
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)
What does input() do?
Reads user input as a string
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)
What built-in Python tool helps you understand where your code crashed?
Traceback
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
True or False: Indentation doesn't matter in Python.
False
What built-in function gives the length of a list?
len()
What keyword can you use to exit a loop early?
break
Fix the bug:
for i in range(5)
print(i)
Missing colon after range(5)
What is the final value of x?
x = 0
for i in range(3):
x += i
3
How do you begin a comment in Python?
#
What does range(5) produce?
How many times does this loop run?
for i in range(2, 10, 2):
print(i)
4
What's a good first step when you see an error?
Read the traceback and check the line it points to
What will this print?
for i in range(5):
if i == 2:
continue
print(i)
0 1 3 4
What's wrong with this code?
x = input("Enter:")
print x
Missing parentheses in print (Python 3 syntax)
What does int() do when used with input?
Converts the string input to an integer