x = 5
x = x + 3
print(x)
8
for i in range(3):
print("Hi")
hi gets repeated 3 times
x = 7
if x > 5:
print("Yes")
else:
print("No")
Yes
if x = 5:
print("Hello")
the code uses = instead of ==
What is a variable?
A named location that stores data.
Question 2 (Medium):
x = 10
y = x - 4
x = y + 2
print(x)
8
total = 0
for i in range(1, 5):
total += i
print(total)
10
x = 10
if x < 5:
print("Low")
elif x < 15:
print("Medium")
else:
print("High")
Medium
for i in range(5)
print(i)
the colon is missing after the “for” statement
What does a loop do in a program?
Repeats a block of code multiple times.
x = 3
y = x * 2
x = y + x
print(x)
9
count = 0
for i in range(2, 10, 2):
count += 1
print(count)
4
x = 8
y = 12
if x > 10 or y < 10:
print("A")
else:
print("B")
B
x = 10
if x > 5:
print("Big")
the print statement is not indented
Loops are used to avoid writing the same code repeatedly.
Repeat a block of code multiple times.