X = 3
Y = 5
print(x + y)
Answer:
8
Explanation:
The program adds 3 and 5, which equals 8.
For i in range(3):
print(i)
Answer:
0
1
2
Explanation:
The loop runs 3 times and prints the number starting from 0
X = 10
If x > 5:
print(“big”)
Else:
print(“small”)
Answer:
Big
Explanation:
Since 10 is greater than 5, it prints “Big”
X = 5
If x = 5:
print(“Equal”)
What is wrong with this code?
What is wrong?:
The if statement uses = instead of ==
Explanation:
= is used to assign a value not compare values. The if statement needs == to check if two values are equal
What is a variable in programming?
Answer:
A variable is used to store information
Explanation:
It holds a value that can be used or changed in the program
Age = 20
If Age > 18:
print (“adult”)
Elif Age < 18:
print(“minor”)
else:
print(“Not valid”)
Answer:
adult
Explanation:
20 is greater than 18 so it will print 18
Total = 0
For i in range (1,4):
Total = total +i
print(total)
Answer:
6
Explanation:
The loops adds 1 + 2 +3 which equals to 6
Num = 7
If num %2 == 0:
Print (“even”)
Else:
print(“odd”)
Answer:
Odd
Explanation:
7 is not cant be divided by 2 so its odd
For i in range (5)
Print (i)
What is wrong with this code?
What is wrong?:
The for loop is missing a colon
Explanation:
A colon is required at the end of the loop statement to show where the loop starts
What does a loop do?
Answer:
It repeats a code multiple times
Explanation:
Instead of writing the same code again, a loop runs it over and over
score = 68
If score >= 90:
print(“A”)
elif score >= 70:
print(“c”)
elif score >= 80:
print(“b”)
elif score >= 65:
print(“d”)
else:
print(“f”)
Answer:
d
Explanation:
68 is only greater than 68 so it could only print d
x=1
For i in range (4):
x=x * 2
Print (y)
Answer:
16
Explanation:
The loop doubles the value of x 4 times
Score = 85
If score >= 90:
prints(“A”)
Elif score >=80:
print(“B”)
Else:
print(“C”)
Answer:
B
Explanation:
85 is not 90 or higher but it is 80 or higher so it prints “B”.
Total = 0
For i in range (1,4)
Total = total + i
Print (total)
What is wrong with this code?
What is wrong?:
The line inside the loop is not indented
Explanation:
Indent is to show what a code belongs inside a loop, Without it, the loop wont work.
What is the purpose of an if/ else statement?
Answer:
It makes decisions in a program
Explanation:
The program checks a condition and runs different code depending on whether its true or false