wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Chapter 1 to Chapter 5 python

Total questions: 45

Worksheet time: 49mins

Name
Class
Date
1.

What symbol is used to write a single-line comment in Python?

a)

//

b)

<!--

c)

#

d)

/*

2.

Which of the following best describes the difference between Python 2 and Python 3?

a)

Python 3 is just a faster version of Python 2.

b)

Python 2 uses print as a function, while Python 3 uses print as a statement.

c)

Python 3 uses print as a function, while Python 2 uses print as a statement.

d)

Python 2 supports more libraries than Python 3.

3.

Write a simple python program to remove duplicate elements from a list.
Input: [1, 2, 2, 3, 4, 4, 5]
Output: [1, 2, 3, 4, 5]

4 lines
4.

Which of the following is the correct extension of a Python file?

a)

.pyth

b)

.pt

c)

.py

d)

.p

5.

Which keyword is used to define a function in Python?

a)

function

b)

def

c)

fun

d)

define

6.

What is the output of: print(type("Hello"))

a)

<type 'string'>

b)

<class 'int'>

c)

<class 'str'>

d)

str

7.

Which of the following is not a valid Python data type?

a)

array

b)

tuple

c)

list

d)

dictionary

8.

What will be the output of print(2 ** 3)?

(a)  

9.

Which of the following is used to take input from the user in Python 3?

(a)  

10.

Which symbol is used for multiplication in Python?

(a)  

11.

Which one of the following is a mutable data type in Python?

a)

tuple

b)

string

c)

list

d)

int

12.

Why is indentation important in Python?

a)

It makes the code look pretty

b)

It is used to define blocks of code

c)

It helps Python ignore errors

d)

It is optional in Python

13.

Which of the following Python scripts correctly asks for a user's name and prints a greeting?

a)

name = input("Enter your name")

print("Hello" + name)

b)

name = get("Enter your name")

print("Hello", name)

c)

input("What is your name?") = name

print("Hi", name)

d)

ask name = input("Enter name")

echo("Hi", name)

14.

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

a)

2ndValue

b)

value 2

c)

my-value

d)

_class2

15.

Which code snippet checks if a number is less than 10 and prints “Smaller”?

a)

if x > 10:

print("Smaller")

b)

if x < 10:

print("Smaller")

c)

if x == 10:

print("Smaller")

d)

if x != 10:

print("Smaller")

16.

What will be the output of the following code?

(a)  

17.

Which of the following correctly swaps the values of a and b?

a)

temp = a

b = a

a = temp

b)

a = b

b = a

c)

a, b = b, a

d)

swap(a, b)

18.

What is the data type of the result of: 7 \\ 2?

a)

int

b)

float

c)

str

d)

double

19.

What will be the value of x after the following code?
x = 10

x += 5

x -= 3

(a)  

20.

What is the output of this code?
x = 2

y = 3

x *= y + 1

print(x)

(a)  

21.

Which of these best describes a statement in Python?

a)

A block of text

b)

A print function

c)

A line of code that performs an action

d)

A set of rules

22.

Predict the output of:
a = 4

b = a + 2

a = b - 1

print(a)

(a)  

23.

Given x = 10, what will print(x % 3) output?

(a)  

24.

Which keyword is used to create a decision-making structure in Python?

a)

select

b)

when

c)

if

d)

switchs

25.

What is the correct syntax for an if-else statement in Python?

a)

if condition:

b)

if condition then:

c)

if (condition) then

d)

if: condition

26.

Which of the following correctly checks if x is between 10 and 20 (inclusive)?

a)

10 <= x <= 20

b)

x >= 10 and x <= 20

c)

x => 10 and x =< 20

d)

x <= 10 or x <= 20

27.

Which keyword is used to check multiple conditions in sequence?

a)

elseif

b)

when

c)

elif

d)

else if

28.

What is the output of this code?
x = 3

if x % 2 == 0:

print("Even")

else:

print("Odd")

(a)  

29.

What is the output?
score = 75

if score >= 90:

grade = "A"

elif score >= 70:

grade = "B"

else:

grade = "C"

print(grade)

(a)  

30.

Which of the following statements about indentation in Python is true?

a)

Indentation is optional in if statements

b)

Indentation is only required in loops

c)

Indentation is required to define blocks in Python

d)

Python uses {} for blocks instead of indentation

31.

What is the output of:

(a)  

32.

What is the result of the condition: not (5 > 3)?

(a)  

33.

What is the logical error in the following code?

a)

Incorrect use of elif

b)

All conditions are checked regardless of earlier ones

c)

The last elif will never run

d)

The structure is correct; no error

34.

You want to check if a number is not between 10 and 20. Which condition is best?

a)

if x < 10 or x > 20:

b)

if x > 10 and x < 20:

c)

if x <= 20 or x >= 10:

d)

if x != 10 and x != 20:

35.

Which condition checks if a variable x is either 0 or a multiple of 5?

a)

if x == 0 or x % 5 != 0:

b)

if x == 0 and x % 5 == 0:

c)

if x == 0 or x % 5 == 0:

d)

if x % 5 == 0:

36.

What is the output of this nested if statement?


(a)  

37.

Identify the issue in this conditional:

4 lines
38.

Which structure is best to check multiple exclusive ranges?

a)

Only if statements

b)

if, elif, and else

c)

if and else only

d)

Nested if inside a loop

39.

What happens if you omit the colon in an if statement?

a)

Prints nothing

b)

Logical error

c)

SyntaxError

d)

RuntimeError

40.

Which output is correct for this?

(a)  

41.

Analyze the following code. The goal is to check if a number is positive, negative, or zero, but the output is incorrect when the number is 0. Identify the logic error and fix the code.

4 lines
42.

Examine the following code. It is intended to calculate the total cost after tax, but the result is wrong. Identify the mistake and correct it.

4 lines
43.

This program is meant to check if a number is divisible by both 3 and 5, but it always prints "Not divisible". Analyze and correct the logic.

4 lines
44.

This program intends to swap two numbers without using a third variable. Analyze the logic and explain if it's correct.

4 lines
45.

Analyze the following expression. What will be the output, and why might this confuse beginners?

4 lines