WorksheetsPython Basics Quiz
Total questions: 30
Worksheet time: 32mins
What will be the output of the following code?
# This is a comment
#print("Hello, World!")
This is a comment
Hello, World!
# This is a comment
Hello, World!
No output
Error
Which of the following is the correct way to write a multiline comment in Python?
/* This is a comment */
// This is a comment
# This is a comment
"""This is a comment"""
What is the data type of the user input in the code below?
x = input("Enter a number: ")
int
float
str
bool
Which line correctly converts the input to an integer?
x = str(input())
x = float(input())
x = int(input())
x = input(int())
What will be the result of the following code?
x = 5 y = "3" print(x + int(y))
8
53
Error
5 + "3"
Which of the following is a valid variable?
2name = "John"
full-name = "John"
running_total = 123
my class = 123
Complete the code to print: My name is Ben and I am 13 years old.?
name = "Ben"
age = 13
print( (a) )
What is the output?
x = 7
if x > 10:
print("High")
elif x > 5:
print("Medium")
else:
print("Low")
Big
Medium
Small
Error
How many times will the following loop run?
for i in range(3, 8):
print(i)
5
6
7
Infinite
What will this code output?
x = 0
while x < 3:
print("Boo!")
x += 1
What will this code output?
x = (6/3)**2
print(x > 2 and x < 6)
(a)
What is the result of " Hello ".strip()?
" hello "
"Hello"
"HELLO"
" HELLO "
Fill in the blank to print dave:
my_name = "Dave"
print (my_name. (a) () )
What does the code return:
word = "Exam - day"
word[2:6] return?
(a)
What is the output of
word = "computer"
word[-1:0:-1]?
"retupmo"
"computer"
Error
"com"
Which expression will return True?
"cat" in "caterpillar"
"dog" not in "hotdog"
"a" in "bcdef"
"b" in "pizza"
What is the result of 3 % 2?
This operator is not used in Python
Which operator returns True only if both conditions are true?
or
not
and
None of the above
What is the output?
mylist = [1, 2, 3, 9, "abc"]
print(mylist[2])
(a)
What will this code print?
mylist = [0, 2, 3]
mylist.append(1)
print(mylist)
What does mylist.clear() do?
Deletes the last element
Removes duplicates
Empties the list
Deletes the list
Fill in the blank:
fruits = ["apple", "banana", "apple", "grape", "kiwi", "red apple", "green apple"]
fruits.count("apple") is going to be: (a)
Fill in the blank:
color["red", "blue", "green"]
print(color.index("blue"))
Error
True
False
Which list method removes an element by index?
remove()
delete()
pop()
cut()
What will be the output?
colors = ["red", "blue"]
colors.insert(1, "green")
colors.sort()
colors.pop(1)
print(colors)
(a)
Which method removes an item by value?
pop()
remove()
del()
erase()
What will be printed?
nums = [1, 2, 3]
nums.insert(1, 4)
nums.clear()
nums.pop(1)
print(nums)
[1, 2, 4]
[ ]
[2, 4, 1]
Error
[1,2,3,4]
What is the output if the user types "Python"?
Welcome
Try again!
Error
Enter your password
What is the output of the code?
(a)
Fill in the blanks to complete the program so it prints only the even numbers between 1 and 10 (inclusive).
(a)
