What symbol is used to start a Python comment?
#
What type of error is caused by forgetting to close a string with quotes?
Syntax Error
What data type is the result of this code?
x = 5 + 3.2
float
Write a Python program to ask the user for their age and store it in a variable.
age = input("How old are you? ")
What is a variable in Python?
A variable is a container for storing data values.
What will this code print?
print("Hello" + "World")
HelloWorld (No space between words).
What type of error will this code produce, and why?
x = 5
y = "7"
z = x + y
Syntax TypeError, because you can’t add an integer (x) to a string (y).
Convert the string "25" into an integer and store it in a variable.
x = int("25")
Write a program that asks the user for their name and then prints a greeting like this:
Hello, [name]!
name = input("What is your name? ") print("Hello, " + name + "!")
What does the int() function do in Python?
Converts a value into an integer.
Fix the syntax error in this code:
print "Welcome to Python!"
print ("Welcome to Python!")
Add parentheses:
Identify and fix the error in this code:
print("The answer is: " + 42)
print("The answer is: " + str(42))
Convert the integer to a string:
What will this code print?
x = 5 y = "5" print(x * y)
55555 (repeats the string 5 times).
Write code to ask the user for two numbers and print their sum.
x = input("Enter the first number: "))
y = input("Enter the second number: ")
print("The sum is: " + int(x) + int(y)
What is the term for fixing errors in your code?
Debugging.
Rewrite this line of code so it runs without error:
name = input("What is your name?"
name = input("What is your name?")
Close the parentheses:
Rearrange the code so it runs correctly:
print("The sum is: ", x + y)
x = 5
y = 10
x = 5
y = 10
print("The sum is: ", x + y)
What will this code print, and why?
x = "7" * 3
print(x)
It will print 777 because the string "7" is repeated 3 times.
Write a program that asks the user for two numbers, multiplies them, and prints the result.
x = input("Enter the first number: "))
y = input("Enter the second number: ")
print("The product is: " + int(x) * int(y))
What does the input() function do in Python?
Prompts the user for input and returns it as a string.
Write a Python program that stores your first name and last name in variables and prints them in the format: LastName, FirstName.
first_name = "YourFirstName"
last_name = "YourLastName"
print(last_name + ", " + first_name)
Why does the following code crash? How would you fix it?
value = int(input("Enter a number: "))
print("Your number is " + value)
Fix it by converting the integer to a string:
value = int(input("Enter a number: "))
print("Your number is " + str(value))
Explain what the following code does:
x = float("25") + int("30")
Converts the string "25" to a float, converts "30" to an integer, and adds them. The result is 55.0 (a float).
Write a program that asks the user for their name and age, then prints this sentence:
[Name] is [Age] years old.
name = input("What is your name? ")
age = input("How old are you? ")
print(name + " is " + age + " years old.")
What is the difference between a function and a variable?