wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Quiz 2 - ComProg1 - MakScie

Total questions: 50

Worksheet time: 50mins

Name
Class
Date
1.

What is the output of 7 // 3 in Python?

a)

2.33

b)

2

c)

3

d)

2.0

2.

Which operator has the highest precedence in Python?

a)

*

b)

+

c)

**

d)

%

3.

What is the result of 15 % 4?

a)

3

b)

4

c)

1

d)

2

4.

Which of the following will return True?

a)

5 == '5'

b)

5 is 5.0

c)

5 != 6

d)

'a' > 'z'

5.

Which of these operators is used for exponentiation in Python?

a)

^

b)

**

c)

^^

d)

exp

6.

What is the result of 2 ** 3 ** 2?

a)

64

b)

512

c)

256

d)

8

7.

Which of the following evaluates to False?

a)

not (5 > 3)

b)

(4 < 10) and (10 > 2)

c)

(6 == 6) or (7 < 2)

d)

5 <= 5

8.

What will 10 / 3 return in Python 3?

a)

3

b)

3.0

c)

3.33…

d)

Error

9.

What is the output of 9 & 12 (bitwise AND)?

a)

12

b)

8

c)

9

d)

0

10.

Which operator is used for floor division?

a)

/

b)

//

c)

%

d)

div

11.

What is the output of True + False?

a)

0

b)

1

c)

2

d)

Error

12.

What is the result of ~5 (bitwise NOT)?

a)

5

b)

-5

c)

-6

d)

6

13.

Which of the following is NOT a valid logical operator?

a)

and

b)

or

c)

xor

d)

not

14.

If a = 7, which expression evaluates to True?

a)

a % 2 == 0

b)

a // 3 == 2

c)

a ** 2 < 40

d)

a < 5

15.

What does a += 5 mean?

a)

a = a + 5

b)

a = a - 5

c)

a = 5

d)

a = a * 5

16.

What is the type of the result of 7 / 2?

a)

int

b)

float

c)

decimal

d)

complex

17.

Which operator is used for identity comparison?

a)

==

b)

is

c)

in

d)

===

18.

What is the output of '5' * 3?

a)

15

b)

555

c)

Error

d)

'53'

19.

Which expression evaluates to True?

a)

'apple' < 'banana'

b)

'Zebra' > 'apple'

c)

'abc' == 'ABC'

d)

len('hi') > 5

20.

What does 10 >> 1 return?

a)

5

b)

20

c)

2

d)

8

21.

What is the output? x = 10 if x > 5: print("A") else: print("B")

a)

A

b)

B

c)

AB

d)

Error

22.

Which keyword is used to end an if block?

a)

endif

b)

break

c)

else

d)

Indentation

23.

What will this print? if False: print("Yes") else: print("No")

a)

Yes

b)

No

c)

Error

d)

Nothing

24.

What is printed? x = 0 if x: print("True") else: print("False")

a)

True

b)

False

c)

Error

d)

None

25.

Which values are treated as False in if conditions?

a)

0

b)

[]

c)

None

d)

All of the above

26.

Identify the correct syntax.

a)

if (x > 5)

b)

if x > 5:

c)

if x > 5 {

d)

if x > 5 then

27.

What is printed? x = 5 if x == 5: print("Equal") else: print("Not equal")

a)

Equal

b)

Not equal

c)

Error

d)

None

28.

What happens if if condition is not indented?

a)

Executes normally

b)

SyntaxError

c)

Prints nothing

d)

Ignores indentation

29.

What is printed? if 'a' in 'cat': print("Yes") else: print("No")

a)

Yes

b)

No

c)

Error

d)

None

30.

What is the output? if 1: print("One") else: print("Zero")

a)

One

b)

Zero

c)

Error

d)

Nothing

31.

In Python, if statements can be combined using:

a)

and/or

b)

with/without

c)

do/while

d)

switch/case

32.

What is printed? x = 10 if x < 5: print("Small") else: print("Large")

a)

Small

b)

Large

c)

Error

d)

Nothing

33.

Which of the following is invalid?

a)

if x:

b)

if not x:

c)

if (x > y):

d)

if x then:

34.

Which statement is correct?

a)

if can exist without else.

b)

else can exist without if.

c)

elif can exist without if.

d)

if requires else.

35.

What is printed? if []: print("List") else: print("Empty")

a)

List

b)

Empty

c)

Error

d)

None

36.

What is printed? x = 3 if x > 5: print("A") elif x == 3: print("B") else: print("C")

a)

A

b)

B

c)

C

d)

None

37.

Which statement is correct about elif?

a)

Can appear before if

b)

Must follow if

c)

Must follow else

d)

Optional in Python

38.

What is printed? x = 8 if x < 5: print("Low") elif x < 10: print("Medium") else: print("High")

a)

Low

b)

Medium

c)

High

d)

Error

39.

Which of these is valid?

a)

if…elif…else

b)

if…else if…else

c)

if…elseif…end

d)

if…elif…end

40.

What is printed? x = 10 if x > 15: print("A") elif x > 5: print("B") else: print("C")

a)

A

b)

B

c)

C

d)

None

41.

How many elif blocks can Python support?

a)

Only 1

b)

2

c)

Unlimited

d)

None

42.

Which is correct nesting?

a)

if…elif…elif…else

b)

if…elif…else if…else

c)

if…elseif…else

d)

if…if…else only

43.

What is printed? x = 0 if x < 0: print("Negative") elif x == 0: print("Zero") else: print("Positive")

a)

Negative

b)

Zero

c)

Positive

d)

None

44.

What is the output? x = 15 if x < 10: print("A") elif x < 20: print("B") elif x < 30: print("C") else: print("D")

a)

A

b)

B

c)

C

d)

D

45.

What is printed? x = 25 if x < 10: print("Small") elif x < 20: print("Medium") else: print("Large")

a)

Small

b)

Medium

c)

Large

d)

Error

46.

Which statement is incorrect?

a)

Only the first matching if/elif executes.

b)

elif prevents multiple matches.

c)

All elif conditions are always checked.

d)

else is optional.

47.

What will be the output? x = 7 if x % 2 == 0: print("Even") elif x % 2 != 0: print("Odd") else: print("None")

a)

Even

b)

Odd

c)

None

d)

Error

48.

What is printed? score = 85 if score >= 90: print("A") elif score >= 80: print("B") else: print("C")

a)

A

b)

B

c)

C

d)

Error

49.

Which of the following is valid?

a)

if x: elif y: else:

b)

if x: else: elif y:

c)

if x: elif y:

d)

if x: pass elif y:

50.

What is printed? x = 12 if x % 3 == 0: print("Divisible by 3") elif x % 4 == 0: print("Divisible by 4") else: print("Other")

a)

Divisible by 3

b)

Divisible by 4

c)

Other

d)

None