wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Exploring Python Fundamentals

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What is the correct way to start a Python program?

a)

Start with 'def main():'

b)

Use 'print("Hello, World!")' as the first line

c)

Begin with 'import this'

d)

Use 'if __name__ == "__main__":' to start the main execution of a Python program.

2.

Which of the following is a valid variable name in Python?

a)

1variable

b)

variable-name

c)

variable name

d)

variable1

3.

How do you take input from a user in Python?

a)

Use the 'input()' function to take input from a user.

b)

Use the 'get_input()' function to take input from a user.

c)

Use the 'scan()' function to take input from a user.

d)

Use the 'read()' function to take input from a user.

4.

What function is used to print output to the console in Python?

a)

print()

b)

output()

c)

console.log()

d)

write()

5.

What is the purpose of the 'input()' function?

a)

To take user input in Python.

b)

To execute a loop in Python.

c)

To define a function in Python.

d)

To read files from the system.

6.

Which of the following is a correct way to use a placeholder in a print statement?

a)

print('The value is {value}')

b)

print('The value is {}'.format(value))

c)

print('The value is %s' % value)

d)

print('The value is value')

7.

What is the output of the following code: print(5 > 3 and 2 < 4)?

a)

2 > 4

b)

5 < 3

c)

True

d)

False

8.

How do you write a conditional statement in Python?

a)

when condition: code

b)

if condition: code else if another_condition: code

c)

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

d)

if condition then code

9.

What keyword is used to define an 'if' statement?

a)

else

b)

when

c)

if

d)

then

10.

What will be the output of the following code: if 10 > 5: print('Yes') else: print('No')?

a)

Yes

b)

No

c)

Definitely not

d)

Maybe

11.

Which of the following is NOT a comparison operator in Python?

a)

=

b)

<=

c)

!=

d)

==

12.

What is the purpose of the 'elif' keyword in Python?

a)

The 'elif' keyword allows for multiple conditional checks in an if-else structure.

b)

The 'elif' keyword is a way to create loops in Python.

c)

The 'elif' keyword is used to define functions in Python.

d)

The 'elif' keyword is used to handle exceptions in Python.

13.

How can you check if a number is even in Python?

a)

n % 2 == 0

b)

n % 2 != 0

c)

n + 2 == 2

d)

n / 2 == 1

14.

What is the output of print('Hello, {}'.format('World'))?

a)

Hello, Universe

b)

Hello, Earth

c)

Hello, Everyone

d)

Hello, World

15.

What is the result of the expression: 3 == 3 and 4 != 5?

a)

4 == 5

b)

true

c)

false

d)

3 == 4

16.

How do you handle multiple conditions in a single if statement?

a)

Use a switch statement for all conditions.

b)

Use nested if statements exclusively.

c)

Only check one condition at a time.

d)

Use logical operators like '&&' for AND and '||' for OR.

17.

What is the output of print('Value: %d' % 10)?

a)

Value: 10

b)

Value: ten

c)

Value: 10.0

d)

Value: 20

18.

Which function can be used to convert a string input to an integer?

a)

int()

b)

parseIntString()

c)

strToInt()

d)

convertToInteger()

19.

What is the syntax for a while loop in Python?

a)

for condition: # code to execute

b)

while (condition) { # code to execute }

c)

repeat until condition: # code to execute

d)

while condition: # code to execute

20.

How do you write a nested if statement in Python?

a)

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

b)

if condition1: # code to execute if condition1 is false

c)

if condition1 and condition2: # code to execute if both conditions are true

d)

if condition1: # code to execute if condition1 is true

21.

What is the correct syntax to define a function in Python?

a)

def function_name():

b)

function function_name():

c)

define function_name():

d)

function_name() = def:

22.

How do you create a list in Python?

a)

list = 1, 2, 3

b)

list = (1, 2, 3)

c)

list = [1, 2, 3]

d)

list = {1, 2, 3}

23.

What is the output of the expression: len('Hello')?

a)

None

b)

5

c)

4

d)

6

24.

What is the output of the following code: print(10 // 3)?

a)

3.33

b)

4

c)

3.0

d)

3

25.

How do you create a dictionary in Python?

a)

dict =

b)

dict = (key: value)

c)

dict = {key: value}

d)

dict = [key: value]

26.

What is the purpose of the 'break' statement in a loop?

a)

To exit the loop immediately.

b)

To pause the loop for a moment.

c)

To skip the current iteration.

d)

To continue to the next iteration.

27.

What is the output of the following code: print(2 ** 3)?

a)

6

b)

8

c)

4

d)

9

28.

How do you create a tuple in Python?

a)

tuple = 1, 2, 3

b)

tuple = {1, 2, 3}

c)

tuple = (1, 2, 3)

d)

tuple = [1, 2, 3]

29.

What is the purpose of the 'continue' statement in a loop?

a)

To skip the current iteration and continue with the next one.

b)

To exit the loop immediately.

c)

To pause the loop for a moment.

d)

To restart the loop from the beginning.

30.

What is the output of the following code: print(10 % 3)?

a)

10

b)

0

c)

1

d)

3