NEW
Font size
WorksheetsPython Programming Quiz
Total questions: 20
Worksheet time: 10mins
What is the purpose of the print() function in Python?
To display output to the console
To read user input
To create a variable
To define a function
Is Python sensitive to whitespace when defining code blocks?
Yes
No
Only in functions
Depends on the operating system
Which symbol is used to create a list in Python?
( )
[ ]
{ }
< >
Which of the following is a valid variable name in Python?
1st_variable
my-variable
myVariable
my variable
How do you start a function definition in Python?
function myFunction():
def myFunction():
create myFunction():
myFunction():
What is the output of the following code? x = 5 print(x * 2)
10
5
25
Error
Which of the following statements assigns the value of 10 to the variable x in Python?
x:=10
let x = 10
x = 10
x ← 10
What will be the output of this code? for i in range(3): print(i)
0 1 2
1 2 3
0 1 2 3
0 1 2 3 4
How do you start writing a for loop in Python?
for each i in x:
for i = 1 to x:
for i in x:
for i > x:
What would be the value of ‘new_score’ after running this code:
score = 44
total = 1
new_score = score * 2
88
44
45
22
What is the output of the following code? print("Hello " * 3)
Hello Hello Hello
Hello 3
Hello Hello Hello 3
Error
Which operator is used to check equality in Python?
==
=
===
!=
How do you start writing a for loop that iterates over a list called items?
for item in items:
for each item in items:
for item: items
foreach item in items:
What will be the output of this code? x = [1, 2, 3] print(len(x))
3
2
1
Error
What is the output of the following code?
def calculate (num1, num2):
answer = num1 * num2
print(answer)
calculate(2, 5)
11
7
10
answer
What will the following code output? x = "Hello" print(x[1])
H
e
Hello
Error
Which of these codes is the correct syntax?
Print ("Hello World")
print ("Hello World")
PRINT ("Hello World")
print "Hello World"
Which built in function can be used in Python to return a string in upper case letters?
toUpper()
upperCase()
capitalize()
upper()
What sort of error occurs when the program runs but you do not get the correct answer you expected?
Answer Error
Syntax Error
Run-time Error
Logical Error
what does this code display:
counter = 1
while counter <4:
print (counter)
counter = counter + 1
1 2 3 4
1 2 3
0 1 2 3
0 1 2 3 4
