input(“Whats your favorite color? ”)
print(“That is a great color!”)
You will type in your favorite color and it will print out “That is a great color!”
Explanation:
The input(“”) allows the user to type in their answer and print(“”) will print out anything that is written in it.
for i in range(3):
print("Hello")
The word Hello prints 3 times.
Explanation:
The loop runs once for each number in range(3).
age = 17
if age >= 18:
print("Adult")
else:
print("Minor")
It prints Minor.
Explanation:
Since 17 is less than 18, the condition is false and the else runs.
if age = 18:
print("You can vote")
What is wrong?:
The = operator is used instead of ==.
Explanation:
= assigns a value, while == compares values in conditions.
What is a variable?
A variable stores data that can change.
Explanation:
Variables hold values so they can be reused later in the program.
slip = input(“Do you have your permission slip yes or no? ”)
if slip == “yes”:
print(“you are able to go on the trip!”)
else:
print(“you can’t go on the trip”)
if you put “yes” for the slip it will print “you are able to go on the trip” but if you put no it will print “you can’t go on the trip”
Explanation:
The if statement checks whether slip equals "yes". If the condition is false, the else block runs.
for i in range(1, 6):
print(i)
It prints the numbers 1 through 5.
Explanation:
range(1, 6) starts at 1 and stops before 6.
score = 85
if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("C")
It prints B.
Explanation:
85 is not 90 or higher, but it is greater than or equal to 80.
for i in range(5)
print(i)
What is wrong?:
The colon : is missing.
Explanation:
Python requires a colon after loops and condition statements.
What does a loop do?
A loop repeats code multiple times.
Explanation:
Loops are used to avoid repeating the same code manually.
x = 5
y = 10
x = y
print(x)
It will print 10.
Explanation:
The value of y (10) is assigned to x, so x no longer equals 5.
total = 0
for i in range(1, 4):
total = total + i
print(total)
It prints 6.
Explanation:
The loop adds 1 + 2 + 3 to total, resulting in 6.
x = 10
if x > 5 and x < 15:
print("Inside")
else:
print("Outside")
It prints Inside.
Explanation:
Both conditions must be true, and 10 is greater than 5 and less than 15.
x = input("Enter a number: ")
if x > 10:
print("Big number")
What is wrong?:
x is a string, not a number.
Explanation:
input() returns a string, so it must be converted to an integer before comparing.
What is the difference between = and ==?
= assigns a value, while == compares values.
Explanation:
Using the wrong one can cause logic or syntax errors.