WorksheetsUnit 1 Post Test: Basic Python
Total questions: 10
Worksheet time: 15mins
Which of the following is the correct syntax to display "Hello, World!" in Python?
print("Hello World!")
console.log("Hello, World!")
print("Hello, World!")
What is the correct way to create a variable in Python and assign the value 10 to it?
int x = 10
var x = 10
num = 10
x := 10
What will be the output of the following code?
print(4 + 5 * 2)
Which of the following is an example of type conversion in Python?
x = str(5)
x = int("5")
x = float("3.14")
All of the above
What does the following code output?
name = "John"
age = 25
print("My name is " + name + " and I am " + str(age) + " years old.")
My name is John and I am 25 years old.
My name is John and I am age 25.
My name is name and I am age 25 years old.
Error
What will the following code output if the user inputs "5"?
<class 'int'>
<class 'str'>
<class 'float'>
Error
Which of the following is the correct way to get user input in Python and store it as an integer?
user_input = int(input("Enter a number: "))
user_input = input("Enter a number: ")
user_input = float(input("Enter a number: "))
user_input = eval(input("Enter a number: "))
What will be the result of the following code?
x = 10
y = 3
print (x - y)
Which of the following concatenates the string "Python" and the number 3.0?
print("Python" + str(3.0))
print("Python" + 3.0)
print("Python" + int(3.0))
print("Python" + float(3.0))
Which of the following is a valid way to convert a float to an integer in Python?
x = int(3.7)
x = float(3.7)
x = str(3.7)
x = bool(3.7)
