What symbol do we use to combine text in print statements?
+
What is a variable?
A container that holds data/value.
What two Boolean values exist in Python?
True and False
What is the main difference between a while loop and a for loop?
While = condition-based; For = count-based.
What is a nested loop?
A loop inside another loop.
Why must we use str() when printing numbers with text?
To convert a number into a string so it can be concatenated.
What is the output?
x = 3 + 4 * 2
11
Fill in the blank: if score >= 90: runs when the score is ___ or higher.
90
Write a loop that prints numbers 1–5.
python
for i in range(1, 6):
print(str(i))
FREE POINTS
FREE POINTS
Predict the output:
word = "Hi" + "!" * 3
print(word)
Hi!!!
Predict the output:
a = 10
b = 5
c = a / b + (a - b) * 2
c = 10 / 5 + (10 - 5) * 2 = 2 + 10 = 12
What will this print?
x = 8
if x % 2 == 0 and x > 5:
print("Pass")
else:
print("Fail")
Pass
What’s the output?
x = 0
while x < 3:
print("Loop")
x = x + 2
“Loop” printed twice (x=0,2).
How many total prints will run?
for outer in range(1, 5):
for inner in range(outer):
print("#")
10 total (1+2+3+4).
What is printed?
greeting = "Hello "
name = "John"
print(greeting + name + "!")
Hello John!
What happens if you forget to convert a number to str() in a print statement?
You get a TypeError, because Python can’t add a string and an integer together.
Predict the output:
age = 16
has_id = False
if age >= 16:
if has_id == True:
print("Allowed")
else:
print("Need ID")
Need ID
What’s printed?
for i in range(2, 11, 3):
print(str(i))
2, 5, 8
Predict the output:
for outer in range(1, 3):
for inner in range(outer, 4):
print("outer=" + str(outer) + " inner=" + str(inner))
outer=1 inner=1
outer=1 inner=2
outer=1 inner=3
outer=2 inner=2
outer=2 inner=3
Explain what happens:
greet = "Hi"
print(greet * 2 + " there")
Output: HiHi there — the string repeats first, then concatenates " there".
Find the value of result:
result = ((8 - 3) * 2 + 10 / 5) - (6 - 4)
(5 * 2 + 2) - 2 = (10 + 2) - 2 = 10
Create a program that asks for a user’s age and prints:
“Teen” if 13–19,
“Child” if under 13,
“Adult” otherwise.
age = int(input("Enter age: "))
if age < 13:
print("Child")
elif age <= 19:
print("Teen")
else:
print("Adult")
Explain what happens: print? stop? iterations?
num = 10
while num > 2:
num = num - 3
print("Num = " + str(num))
Prints: 7, 4, 1 — stops when num ≤ 2. (3 total iterations.)
Challenge: Write a nested loop that prints this number triangle:
1
12
123
1234
for outer in range(1, 5):
row = ""
for inner in range(1, outer + 1):
row = row + str(inner)
print(row)