NEW
Font size
WorksheetsPython Basics Quiz
Total questions: 20
Worksheet time: 10mins
What is the correct way to declare a variable in Python?
a) x : int = 5
b) int x = 5
c) x = 5
d) declare x = 5
Which of the following is NOT a valid variable name?
a) student_name
b) 3score
c) _age
d) price$
What is the data type of the following variable? num = 10.5
a) int
b) float
c) str
d) bool
What will be the output of the following code? x = "10" y = 5 print(x + y)
a) 15
b) 105
c) Error
d) "10 5"
Which of the following data types can store decimal numbers?
a) int
b) bool
c) float
d) str
What will be the output of the following code? print("Hello", "World", sep="-")
a) Hello-World
b) Hello World
c) Hello, World
d) Hello- World
What will be the output of print(5, 10, 15, end="!")?
a) 5 10 15
b) 5 10 15!
c) 5, 10, 15
d) Error
How do you print a double quote (") inside a string?
a) print("He said, "Hello"")
b) print('He said, "Hello"')
c) print("He said, \"Hello\"")
d) Both b and c
What will print("Python\nRocks") output?
a) Python Rocks
b) PythonRocks
c) Python Rocks
d) Error
What is the default separator in the print() function?
a) -
b) ,
c) " " (space)
d) None
What does the input() function return?
a) int
b) float
c) str
d) Depends on the input
How can you take an integer input from the user?
a) num = input(int())
b) num = int(input())
c) num = input(int)
d) num = int(input(int()))
What will happen if the user enters "Hello" in the following code? num = int(input("Enter a number: "))
a) num will store "Hello" as a string
b) The program will crash with an error
c) num will store 0
d) The program will print "Hello"
What is the correct way to prompt the user for their name and print it?
a) name = input("Enter your name: ") print("Hello", name)
b) name = input print("Hello", name)
c) input("Enter your name: ") = name print("Hello", name)
d) None of the above
What will be the output of the following code if the user enters 10? num = input("Enter a number: ") print(num * 2)
a) 20
b) 1010
c) Error
d) 10 10
What is the output of print(10 // 3)?
a) 3.33
b) 3
c) 3.0
d) 4
What will print(2 ** 3) output?
a) 5
b) 6
c) 8
d) 9
Which of the following operators is used for modulus (remainder)?
a) %
b) //
c) /
d) **
What is the result of print(5 + 3 * 2)?
a) 11
b) 16
c) 13
d) 10
What will be the output of print(5 / 2)?
a) 2.5
b) 2
c) 3
d) 2.0
