WorksheetsPython Programming Quiz
Total questions: 25
Worksheet time: 25mins
Which of the following best describes Python?
Python is a low-level, compiled programming language.
Python is an interpreted, high-level programming language.
Python is only used for web development.
Python cannot be used for automation.
Which of the following are examples of floating-point literals in Python? (Select all that apply)
3.14
0.0
3
-2.5
What is the purpose of the `input()` function?
To display output to the user.
To perform calculations.
To receive input from the user.
To define a new variable.
What is the result of `5 + 3 * 2` in Python?
16
11
13
8
What is the output of `5 >> 1`?
10
2
0
3
Which of the following are valid uses of logical operators? (Select all that apply)
`True and False`
`not True`
`True or False`
`True xor False`
What will `3 != 4` return?
True
False
Error
None
Complete the expression to convert the string `'123'` into an integer:
(a)
What is the output of `print("A", "B", sep="-")`?
A B
A-B
AB
A, B
What is the result of `len(str(100))`?
100
1
3
0
Which keyword is used to execute a block of code multiple times?
if
loop
for
repeat
What is the purpose of `continue` in a loop?
To skip the rest of the loop and continue to the next iteration.
To exit the loop.
To pause the loop.
To restart the loop.
Which of these loop structures are valid in Python? (Select all that apply)
`for i in range(5):`
`while i < 10:`
`do while i < 10:`
`foreach i in list:`
What will this code print?
for i in range(3):
if i == 1:
break
print(i)
0
1 2
0 1 2
0 1
What is a nested loop?
A loop with many conditions
A loop that runs after another loop finishes
A loop inside another loop
A loop that repeats forever
Which method can be used to add an item to a list?
insertFirst()
push()
append()
add()
What is the output of this code?
my_tuple = ("a", "b", "c")
print(my_tuple[2])
a
b
c
Error
Which of the following is NOT allowed for a tuple?
Indexing
Slicing
Modifying elements
Iterating
Which of the following are dictionary methods? (Select all that apply)
keys()
items()
values()
length()
What does this code do?
my_dict = {"x": 1, "y": 2}
print("z" in my_dict)
Prints the value of key "z"
Returns True
Returns False
Throws an error
What is the purpose of the `return` statement in a function?
It ends the function and returns a value.
It pauses the function.
It exits the loop.
It prints the result.
What is `None` in Python?
A keyword that means zero
A keyword that means empty string
A special constant representing no value
A syntax error
Which of the following are valid ways to pass arguments to a function? (Select all that apply)
Positional
Keyword
Mixed
Static
Which of the following is true about recursion?
A function cannot call itself
It is the same as iteration
A recursive function must have a base case
Recursive functions are not allowed in Python
What will the following code output?
try:
print(1 / 0)
except:
print("Division by zero")
1
0
Division by zero
Error
