wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

PYTHON "If" Statement

Total questions: 11

Worksheet time: 6mins

Name
Class
Date
1.

In Python, what are if-statements used for?

a)

Looping

b)

Indexing

c)

Decision Making

d)

Testing

2.

What is the output of this code?


click = True

Like = 0

if click:

Like = Like + 1

print(Like)

a)

0

b)

1

c)

2

d)

3

3.

What is the output of the following code?


What is the output of following code

Temperature = 20

Thermo = 15

if Temperature < 15:

Thermo = Thermo + 5

print(Thermo)

a)

20

b)

15

c)

25

d)

10

4.

What is the output of the following code?


Time = "Day"

Sleepy = False

Pajamas = "Off"

if Time == "Night" and Sleepy == True:

Pajamas = "On"

print(Pajamas)

a)

off

b)

on

c)

False

d)

Day

5.

What will be the output of the following code?


def max(a, b):

if a > b:

print('a is the max')

else:

print('b is the max')


max(1,2)

a)

1 is the max

b)

a is the max

c)

2 is the max

d)

b is the max

6.

Which of the following statements are correct?

(Select 2 Answers)

a)

If is a conditional statement

b)

If is used for looping

c)

If is used for comparing and decision making

d)

If is used for error handling

7.

What will the be the output of the following code?


if (10<0) and (0 <-10):

print(“A”)

else:

print(“B”)

a)

A

b)

B

c)

AB

d)

BA

8.

Is the following statement true or false?


More than one condition cannot be used with an IF statement.

a)

True

b)

False

9.

Is the following statement True of False?

Boolean variables can be used as conditions in an IF statement.

a)

True

b)

False

10.

What is the output of the following code?


a = "b"

if True or True:

a = "a"

print(a * 2)

a)

bb

b)

aa

c)

ab

d)

ba

11.

The result of this program:

Friday = False

if Friday:

print "Jeans day!"

else:

print "Uniform day"

a)

Jeans day

b)

Today is Friday

c)

Uniform day

d)

Not Friday