Write Python code that displays:
Hello, World!
print("Hello, World!")
Ask the user to enter their name.
name = input("Enter your name: ")
What is the output?
print(5 + 3)
8
Complete the code:
age = 15
if age >= 13:
____________
Make it display:
Teenager
print("Teenager")
Find the error:
print("Hello"
Missing closing parenthesis:
print("Hello")
Write one line of code that displays:
Hello 5
print("Hello", 5)
Ask the user for their age and store the answer in age.
age = input("Enter your age: ")
What is the output?
print(10 % 3)
1
Complete the condition so the program prints "Adult" when age is 18 or older.
age = 20
if ____________:
print("Adult")
age >= 18
Find the error:
if age >= 13
print("Teenager")
Missing colon after the condition.
Correct:
if age >= 13:
print("Teenager")
Create a variable called age and store the value 15.
age = 15
The user enters:
Ana
What will this display?
name = input("Enter your name: ")
print(type(name))
<class 'str'>
What is the output?
print(7 // 2)
3
Complete the code:
score = 85
if score >= 90:
grade = "A"
elif ____________:
grade = "B"
else:
grade = "C"
score >= 80
What will this display?
x = "5"
y = 5
print(x == y)
False
Because "5" is a string while 5 is an integer.
Create three variables:
name = Ana
age = 15
grade = 8
Then print them.
name = "Ana"
age = 15
grade = 8
print(name)
print(age)
print(grade)
The user enters 5.
What is wrong with this program?
num = input("Enter a number: ")
print(num + 1)
input() returns a string, so num contains "5" rather than the integer 5.
What is the output?
print(2 ** 3)
8
What will this display?
age = 15
print(age >= 13 and age <= 19)
True
What will this display?
count = 0
count = count + 1
print(count)
1
Write a program that stores:
name = Ana
age = 15
and displays:
My name is Ana and I am 15 years old.
name = "Ana"
age = 15
print("My name is", name, "and I am", age, "years old.")
Fix the program so the user can enter a number and the program adds 1.
num = input("Enter a number: ")
print(num + 1)
num = int(input("Enter a number: "))
print(num + 1)
Without running the code, determine the output:
print(5 + 3 * 2)
11
Why?
Multiplication happens before addition:
3 × 2 = 6
5 + 6 = 11
Write a program that asks for a score.
If the score is:
score = int(input("Enter your score: "))
if score >= 90:
print("Excellent")
elif score >= 80:
print("Good")
else:
print("Needs Improvement")
Fix this entire program:
name = input("Enter your name: ")
age = input("Enter your age: ")
if age >= 18
print(name, "is an adult")
else:
print(name, "is a minor")
name = input("Enter your name: ")
age = int(input("Enter your age: "))
if age >= 18:
print(name, "is an adult")
else:
print(name, "is a minor")