wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

MidtermExam-ComProg1-MakScie

Total questions: 100

Worksheet time: 2hrs 40mins

Name
Class
Date
1.

What will be the type of variable x? x = 3.14

a)

int

b)

float

c)

str

d)

complex

2.

Which of the following creates a complex number in Python?

a)

x = 5+2j

b)

x = complex(5,2)

c)

Both a and b

d)

None

3.

What will be printed?

a = True

b = False

print(type(a+b))

a)

int

b)

bool

c)

float

d)

str

4.

Which of these is mutable?

a)

tuple

b)

list

c)

str

d)

int

5.

What will be the result? x = "Python" print(len(x))

a)

6

b)

5

c)

7

d)

8

6.

Which is valid variable name in Python?

a)

2num

b)

_count

c)

num@var

d)

for

7.

What will this print? x = "123" print(type(int(x)))

a)

str

b)

int

c)

float

d)

bool

8.

Which function gives memory address of variable?

a)

address()

b)

id()

c)

loc()

d)

pos()

9.

Output? x = None print(type(x))

a)

NoneType

b)

Null

c)

Object

d)

Undefined

10.

Which is immutable?

a)

List

b)

Set

c)

Dictionary

d)

String

11.

Q11. a = 10 b = a a = 20 print(b)

a)

10

b)

20

c)

None

d)

Error

12.

Which is used for dynamic typing?

a)

C

b)

Java

c)

Python

d)

C++

13.

print(type([1,2,3]) is list)

a)

True

b)

False

14.

print(isinstance((1,2,3), tuple))

a)

True

b)

False

c)

None

d)

1

15.

dict stores elements as:

a)

key-value pairs

b)

only values

c)

only keys

d)

ordered sequence only

16.

What will input() return by default?

a)

int

b)

float

c)

str

d)

None

17.

x = input("Enter: ")

print(type(x))

User enters 25.

Output type?

a)

str

b)

int

c)

float

d)

bool

18.

name = "Alice"

age = 25

print(f"My name is {name} and I am {age} years old.")

Output?

a)

My name is Alice and I am 25 years old.

b)

Error

19.

Which statement is correct for formatted output?

a)

print("Age: %d" % 25)

b)

print("Age: {}.format(25)")

c)

Both a and b

d)

None

20.

Output? print("Hello", "World", sep="-")

a)

Hello World

b)

Hello-World

c)

Hello,World

d)

Error

21.

print("Hello", end="*") print("World")

a)

Hello World

b)

Hello*World

c)

Hello World

d)

Error

22.

x = 10 y = 20 print("Sum is", x+y)

a)

Sum is 1020

b)

Sum is 30

23.

print("{0} {1}".format("Python", "Rocks"))

a)

Rocks Python

b)

Python Rocks

c)

Error

d)

None

24.

Which reads input as integer?

a)

x = int(input())

b)

x = input(int)

c)

x = read(int)

d)

None

25.

What will happen? print("5" + "5")

a)

10

b)

55

c)

Error

d)

None

26.

Output? print(5 // 2)

a)

2.5

b)

2

c)

3

d)

Error

27.

Output? print(7 % 3)

a)

1

b)

2

c)

3

d)

Error

28.

What will be printed? x = 2 ** 3 print(x)

a)

6

b)

8

c)

9

d)

Error

29.

Which operator has highest precedence?

a)

+

b)

-

c)

**

d)

//

30.

x = 10 x += 5 print(x)

a)

10

b)

15

c)

5

d)

Error

31.

print(10 == 10.0)

a)

True

b)

False

32.

print(True + True)

a)

1

b)

2

c)

TrueTrue

d)

Error

33.

Which is a logical operator in Python?

a)

&&

b)

||

c)

and

d)

bitand

34.

print(4 & 5) (BINARY AND)

a)

4

b)

5

c)

1

d)

0

35.

print(4 | 5) (BINARY OR)

a)

4

b)

5

c)

1

d)

5

36.

Which is the identity operator?

a)

is

b)

==

c)

=

d)

!=

37.

Output?

x = [1,2,3]

y = [1,2,3]

print(x is y)

a)

True

b)

False

38.

Output? x = [1,2,3] y = x print(x is y)

a)

True

b)

False

39.

Output? print(3 not in [1,2,4])

a)

True

b)

False

40.

a = 10

b = 20

print(a if a > b else b)

a)

10

b)

20

c)

Error

d)

None

41.

x = 5 if x % 2 == 0: print("Even") else: print("Odd")

a)

Even

b)

Odd

c)

Error

d)

None

42.

Output?

x = 10

if x > 5:

print("A")

elif x > 8:

print("B")

else:

print("C")

a)

A

b)

B

c)

C

d)

Error

43.

Which keyword is used in Python conditional branching?

a)

switch

b)

case

c)

if

d)

when

44.

x = 0

if x:

print("True")

else:

print("False")

a)

True

b)

False

45.

score = 85

if score >= 90:

print("A")

elif score >= 80:

print("B")

else:

print("C")

a)

A

b)

B

c)

C

46.

Output?

x = 3

if x > 5:

    print("A")

else:

    if x > 2:

        print("B")

    else:

        print("C")

a)

A

b)

B

c)

C

47.

if True and False: print("Yes") else: print("No")

a)

Yes

b)

No

48.

if not 0: print("Pass") else: print("Fail")

a)

Pass

b)

Fail

49.

x = 7

if x % 2 == 0:

print("Divisible by 2")

elif x % 3 == 0:

print("Divisible by 3")

else: print("Other")

a)

Divisible by 2

b)

Divisible by 3

c)

Other

50.

Which is correct ternary operator syntax?

a)

if condition ? a : b

b)

a if condition else b

c)

a when condition else b

d)

None

51.

x = "yes" if x: print("True branch")

a)

True branch

b)

Nothing

c)

Error

52.

if "apple" in "pineapple": print("Found")

a)

Found

b)

Nothing

53.

Which values are treated as False?

a)

0

b)

None

c)

""

d)

All above

54.

x = -1 if x: print("Valid")

a)

Valid

b)

Nothing

55.

x = 15

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

print("FizzBuzz")

a)

FizzBuzz

b)

Nothing

56.

x = 1 while x <= 3: print(x) x += 1

a)

1 2 3

b)

0 1 2

c)

Infinite

d)

Error

57.

What happens if condition is always True?

a)

Executes once

b)

Infinite loop

c)

Error

d)

None

58.

x = 0 while x < 5: x += 2 print(x)

a)

4

b)

5

c)

6

d)

Error

59.

Which keyword exits loop?

a)

continue

b)

exit

c)

break

d)

stop

60.

x = 0

while x < 3:

    print(x)

    x += 1

else:

    print("Done")

What is the output of the above code?

a)

0 1 2 Done

b)

1 2 3 Done

c)

0 1 2 3 Done

d)

0 1 Done

61.

What is the output of the following code? for i in range(3): print(i, end=" ") else: print("Done")

a)

0 1 2

b)

0 1 2 Done

c)

Done only

d)

Error

62.

count = 0 while count < 3: count += 1 if count == 2: continue print(count)

a)

1 2 3

b)

1 3

c)

2 3

d)

None

63.

Which loop is entry-controlled?

a)

while

b)

for

c)

Both

d)

None

64.

x = 10 while x > 0: print(x, end=" ") x //= 2

a)

10 9 8 ...

b)

10 5 2 1

65.

n = 123 sum = 0 while n > 0: sum += n % 10 n //= 10 print(sum)

a)

6

b)

7

c)

5

d)

Error

66.

while False: print("Hello")

a)

Hello

b)

Nothing

c)

Error

67.

i = 1 while i < 5: print(i, end=" ") i += 2

a)

1 2 3 4

b)

1 3

68.

x = 5 while x: print(x) x -= 1

a)

5 4 3 2 1

b)

5 4 3 2 1 0

c)

Infinite

d)

None

69.

Which is valid infinite loop?

a)

while True: pass

b)

for i in range(): pass

c)

loop forever

d)

None

70.

i = 0 while i < 5: print("Hi") break

a)

Hi (once)

b)

Hi (five times)

c)

Nothing

d)

Error

71.

i = 0 while i < 3: print(i) i += 1

a)

0 1 2

b)

1 2 3

c)

0 1 2 3

d)

Error

72.

for i in range(3): print(i)

a)

1 2 3

b)

0 1 2

c)

0 1 2 3

d)

Error

73.

What does range(5) generate?

a)

0,1,2,3,4,5

b)

1,2,3,4,5

c)

0,1,2,3,4

d)

None

74.

for i in range(2, 6): print(i, end=" ")

a)

2 3 4 5

b)

2 3 4 5 6

c)

1 2 3 4

d)

Error

75.

for i in range(2, 10, 3): print(i, end=" ") Which of the above is the correct output?

a)

a) 2 3 4 5 6 7 8 9

b)

b) 2 5 8

c)

c) 2 4 6 8

d)

d) Error

76.

Which is valid loop over a list?

a)

for i in [1,2,3]:

b)

for (i=0; i<3; i++):

c)

loop i in [1,2,3]

d)

None

77.

for ch in "Hi": print(ch)

a)

Hi

b)

H i

c)

Error

78.

for i in range(3): print("Yes") else: print("Done") What is the output of the above code?

a)

Yes Yes Yes

b)

Yes Yes Yes Done

c)

Done only

d)

Error

79.

for i in range(1,5):

    if i == 3:

        break

    print(i)

What is the ouput?

(a)  

80.

for i in range(5):

    if i % 2 == 0:

        continue

    print(i)

What is the output?

(a)  

81.

for i in range(3):

    pass

print(i)

What is the output?

(a)  

82.

for i in range(5, 0, -2):

    print(i, end=" ")

What is the output?

(a)  

83.

nums = [10,20,30]

for n in nums:

    print(n//10)

What is the output?

(a)  

84.

for i in range(len("Python")):

    print(i, end=" ")

What is the Output?

(a)  

85.

for i in [1,2,3]:

    print(i*i)

What is the output?

(a)  

86.

for i in "123":

    print(int(i) + 1)

What is the output?

(a)  

87.

for i in range(1,4):

    for j in range(1,3):

        print(i,j)

How many pairs are printed?

(a)  

88.

for i in range(2):

    for j in range(2):

        print(i+j)

What is the output?

(a)  

89.

What is printed?

for i in []:

    print("Loop")

print("End")

(a)  

90.

for i in range(3):

    for j in range(2):

        if j == 1:

            break

        print(i, j)

What is the output?

(a)  

91.

Which is faster for iterating over lists in Python?

(a)  

92.

x = [1,2,3]

for i in x:

    if i % 2 == 0:

        print("Even")

    else:

        print("Odd")

What is the Output?

(a)  

93.

s = "Python"

count = 0

for ch in s:

    if ch in "aeiou":

        count += 1

print(count)

What is the output?

(a)  

94.

total = 0

for i in range(1,6):

    if i % 2 == 0:

        continue

    total += i

print(total)

What is the output?

(a)  

95.

i = 0

while i < 4:

    i += 1

    if i == 3:

        break

print(i)

What is the output?

(a)  

96.

n = 1234

rev = 0

while n > 0:

    rev = rev*10 + n%10

    n //= 10

print(rev)

What is the output?

(a)  

97.

x = [1,2,3,4]

sum = 0

for n in x:

    sum += n

print(sum)

What is the output?

(a)  

98.

for i in range(1,4):

    for j in range(1,3):

        if i == 2 and j == 1:

            continue

        print(i,j)

How many pairs printed?

(a)  

99.

for i in range(1,6):

    if i % 2 == 0:

        print(i*i)

What is the output?

(a)  

100.

n = 5

fact = 1

for i in range(1, n+1):

    fact *= i

print(fact)

What is the output?

(a)