Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Parvez Ahmed - The Ultimate Python Quiz Book - 2024

.pdf
Скачиваний:
2
Добавлен:
07.04.2024
Размер:
6.11 Mб
Скачать

Data Types - 02

250 Python Quizzes

08. Which value would become False when converted to a boolean value?

A)[0]

B)1.0e0

C)1+0j

D)(0)

09. What is the output of the following code?

dic = {5: 10, 6: 12} print(tuple(dic))

A)(10, 12)

B)(5, 6)

C)(5, 10, 6, 12)

D)Error

10. What is the output of the following code?

b = True + True print(b)

A)2

B)TrueTrue

C)1

D)True

020

Operators and Expressions

250 Python Quizzes

Operators and Expressions

01. Which of the following is not a comparison operator?

A)!=

B)<<

C)>=

D)==

02. What is the output of the following code?

s = 'HdaPKwTb'

a = 'ab' not in s b = 'p' in s print(a, b)

A)True False

B)True True

C)False False

D)False True

03. What is the output of the following code?

x = 35 y = 40 x += y y *= 2

print(x, y)

A)35 70

B)75 150

C)35 40

D)75 80

021

Operators and Expressions

250 Python Quizzes

04. Which of the following denotes the bitwise OR operator?

A)&

B)or

C)|

D)=

05. Which of the following operators has right-to-left associativity in Python?

A)**

B)<

C)not

D)is

06. What is the output of the following code?

print(not 5<=3 or 4>4 and 8==8)

A)1

B)True

C)False

D)0

07. What is the output of the following code?

print(7 - 5 * (3 > 4) + 2)

A)0

B)2

C)9

D)5

022

Operators and Expressions

250 Python Quizzes

08. Which among the following operators has the lowest precedence?

A)**

B)+

C)and

D)in

09. What is the output of the following code?

print(2 ** 3 ** 2)

A)512

B)64

C)256

D)16

10. What is the output of the following code?

m = [1, 2] n = [1, 2] o = 10

p = 10

print(m is n, o is p)

A)True False

B)True True

C)False False

D)False True

023

Decision-Making Statements

250 Python Quizzes

Decision-Making Statements

01. What is the recommended number of spaces used for indentation in Python?

A)2

B)4

C)1

D)8

02. What is the output of the following code if the input of x is 9?

x = input() if x != 9:

print(x, end=' ') print(7)

A)7 9

B)9

C)7

D)9 7

03. What is the output of the following code?

k = 15

if k = 13: print(k + 2)

else:

print(k - 2)

A)13

B)11

C)15

D)Error

024

Decision-Making Statements

250 Python Quizzes

04. Which block is an optional alternative to the if block that must also have a condition?

A)else

B)elif

C)if

D)case

05. What is the output of the following code?

print(1 if 3 <= 1 else 3)

A)False

B)3

C)1

D)Error

06. What is the output of the following code?

a = 3

if a - 3:

print(a * a)

else:

print(a + a)

A)6

B)0

C)9

D)Error

07. Which character is used as a wildcard pattern in a match-case statement?

A)Underscore (_)

B)Asterisk (*)

C)Pipeline (|)

D)Percentage (%)

025

Decision-Making Statements

250 Python Quizzes

08. What is the output of the following code if the input of m is 2?

m = int(input()) match m:

case 1:

print(3, end=' ') case 2:

print(1, end=' ') case 3:

print(2, end=' ')

print(m)

A)1 2

B)3 2

C)2 1

D)2 2

09. Fill the question mark with the correct condition to get the given output.

r = 25 if ?:

print(r, end=' ') print(r * 2)

Output: 25 50

A)r % 2 == 0

B)r % 5 != 0

C)r % 2 == 1

D)r % 5 == 1

026

Decision-Making Statements

250 Python Quizzes

10. What is the output of the following code?

b = int('D', 16) match b - 1:

case 11 | 14: print('Gold', end=' ')

case 13 | 10: print('Silver', end=' ')

case 12 | 15: print('Bronze', end=' ')

print(b)

A)Bronze 13

B)Gold 14

C)Silver 13

D)Bronze 12

027

Looping Statements

250 Python Quizzes

Looping Statements

01. What is the output of the following code?

s = 4

while s < 9: s = s + 1

print(s, end='-')

A)4-5-6-7-8-

B)5-6-7-8-

C)4-5-6-7-8-9-

D)5-6-7-8-9-

02. What is the output of the following code?

lis = [[8, 7], [6, 5]] for p, q in lis:

print(p + q, end='&')

A)15&11&

B)26&

C)14&12&

D)Error

03. How many times does the given loop get executed?

for k in range(3, 9, 2):

print(k, end=' ')

A)5

B)3

C)6

D)4

028

Looping Statements

250 Python Quizzes

04. What is the output of the following code?

for i in range(1): print(i, end=' ')

A)1

B)0 1

C)Blank Output

D)0

05. Fill the question mark with the suitable code to get the given output.

for z in ?:

print(z, end=' ')

Output: 7 5

A)range(7, 5, -2)

B)range(4, 7, -2)

C)range(5, 7, -2)

D)range(7, 3, -2)

06. What is the output of the following code?

a = 6

while a > 8:

print(a, end=' ') a = a - 1

A)Infinite Loop

B)6 7

C)Blank Output

D)Error

029