x = 5
y = 10
z = x + y
print(z)
15
in range(3)for i :
print(i)
0, 1, and 2
x = 5
if x > 3:
print("Yes")
else:
print("No")
yes
for i in range(5)
print(i)
add the ":" otherwise the program won't
What is a variable in programming?
A variable is a container used to store data values.
x = 3
y = 4
z = x * y
x = z + 2
print(x)
14
total = 0
for i in range(1, 5):
total += i
print(total)
10
x = 10
y = 20
if x == y:
print("Equal")
else:
print("Not Equal")
not equal
x = 10
if x = 5:
print("Equal")
The operator, =, is used instead of ==
What does a loop do in a program?
A loop repeatedly runs a block of code while a condition is true or for a set number of times.
x = 2
y = 3
for i in range(1, 4):
x += y
y -= 1
print(x)
The loop runs 3 times, starting with x = 2 and y = 3
sum = 0
for i in range(1, 6, 2):
sum += i
print(sum)
9
x = 10
y = 3
if x % y == 1:
print("Remainder is 1")
elif x % y == 2:
print("Remainder is 2")
else:
print("Remainder is 0 or greater than 2")
The remainder is 1.
total = 0
for i in range(1, 5):
total += i
print(total)
The third line isn’t indented properly.
What is the difference between = and == in Python?
= assigns a value to a variable, while == compares two values.