NEW
Font size
WorksheetsExploring Python Fundamentals
Total questions: 30
Worksheet time: 15mins
What is the correct way to start a Python program?
Start with 'def main():'
Use 'print("Hello, World!")' as the first line
Begin with 'import this'
Use 'if __name__ == "__main__":' to start the main execution of a Python program.
Which of the following is a valid variable name in Python?
1variable
variable-name
variable name
variable1
How do you take input from a user in Python?
Use the 'input()' function to take input from a user.
Use the 'get_input()' function to take input from a user.
Use the 'scan()' function to take input from a user.
Use the 'read()' function to take input from a user.
What function is used to print output to the console in Python?
print()
output()
console.log()
write()
What is the purpose of the 'input()' function?
To take user input in Python.
To execute a loop in Python.
To define a function in Python.
To read files from the system.
Which of the following is a correct way to use a placeholder in a print statement?
print('The value is {value}')
print('The value is {}'.format(value))
print('The value is %s' % value)
print('The value is value')
What is the output of the following code: print(5 > 3 and 2 < 4)?
2 > 4
5 < 3
True
False
How do you write a conditional statement in Python?
when condition: code
if condition: code else if another_condition: code
if condition: # code to execute if condition is true elif another_condition: # code to execute if another_condition is true else: # code to execute if none of the above conditions are true
if condition then code
What keyword is used to define an 'if' statement?
else
when
if
then
What will be the output of the following code: if 10 > 5: print('Yes') else: print('No')?
Yes
No
Definitely not
Maybe
Which of the following is NOT a comparison operator in Python?
=
<=
!=
==
What is the purpose of the 'elif' keyword in Python?
The 'elif' keyword allows for multiple conditional checks in an if-else structure.
The 'elif' keyword is a way to create loops in Python.
The 'elif' keyword is used to define functions in Python.
The 'elif' keyword is used to handle exceptions in Python.
How can you check if a number is even in Python?
n % 2 == 0
n % 2 != 0
n + 2 == 2
n / 2 == 1
What is the output of print('Hello, {}'.format('World'))?
Hello, Universe
Hello, Earth
Hello, Everyone
Hello, World
What is the result of the expression: 3 == 3 and 4 != 5?
4 == 5
true
false
3 == 4
How do you handle multiple conditions in a single if statement?
Use a switch statement for all conditions.
Use nested if statements exclusively.
Only check one condition at a time.
Use logical operators like '&&' for AND and '||' for OR.
What is the output of print('Value: %d' % 10)?
Value: 10
Value: ten
Value: 10.0
Value: 20
Which function can be used to convert a string input to an integer?
int()
parseIntString()
strToInt()
convertToInteger()
What is the syntax for a while loop in Python?
for condition: # code to execute
while (condition) { # code to execute }
repeat until condition: # code to execute
while condition: # code to execute
How do you write a nested if statement in Python?
if condition1: if condition2: # code to execute if both conditions are true else: # code to execute if condition1 is true and condition2 is false else: # code to execute if condition1 is false
if condition1: # code to execute if condition1 is false
if condition1 and condition2: # code to execute if both conditions are true
if condition1: # code to execute if condition1 is true
What is the correct syntax to define a function in Python?
def function_name():
function function_name():
define function_name():
function_name() = def:
How do you create a list in Python?
list = 1, 2, 3
list = (1, 2, 3)
list = [1, 2, 3]
list = {1, 2, 3}
What is the output of the expression: len('Hello')?
None
5
4
6
What is the output of the following code: print(10 // 3)?
3.33
4
3.0
3
How do you create a dictionary in Python?
dict =
dict = (key: value)
dict = {key: value}
dict = [key: value]
What is the purpose of the 'break' statement in a loop?
To exit the loop immediately.
To pause the loop for a moment.
To skip the current iteration.
To continue to the next iteration.
What is the output of the following code: print(2 ** 3)?
6
8
4
9
How do you create a tuple in Python?
tuple = 1, 2, 3
tuple = {1, 2, 3}
tuple = (1, 2, 3)
tuple = [1, 2, 3]
What is the purpose of the 'continue' statement in a loop?
To skip the current iteration and continue with the next one.
To exit the loop immediately.
To pause the loop for a moment.
To restart the loop from the beginning.
What is the output of the following code: print(10 % 3)?
10
0
1
3
