0% found this document useful (0 votes)
29 views

Python Assessment-100

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

Python Assessment-100

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

12/14/23, 4:42 PM Python Assessment-100%

Python Assessment-100% Score - 98%

Total Questions - 50

1)

Django is a _____________ Python web framework


A) low-level 1M
B) mid-level
C) high-level
D) None of the above

2) Place the steps performed by the Python interpreter in correct order.


(i) Execute the code

(ii) Compile the code

(iii) Process the programmer’s code sequentially

A) i,ii,iii 1M
B) i,iii,ii
C) iii,ii,i
D) ii,iii,i

3) Which of the following is the correct output on running the below code in Python?
print(“The output is:”)

print(“Hello!”)

A) The output is: Hello! 1M


B) Syntax error
C) Runtime error
D) None of the above

4) Which of the following gives the output as False? 1M


A) '5.0'==5.0
B) 5.0==5
https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 1/19
12/14/23, 4:42 PM Python Assessment-100%

C) 5.1>5
D) None of the above

5) Which of the following coding blocks give an error?

A) 9.1>'9.1' 1M
B) '9'>'9.1'
C) 9!='9'
D) Both a and c

6) Identify the output of the following code.

print(2**1*3,end=” “)
print(2*1**3)

A) 2 2 1M
B) 6 2
C) 6 6
D) 2 6

7) .Find the output of the following code.

str1=str(1234)
str2=’1234′
print(str1==str2,end=” “)
print(str1 is str2)

A) True True 1M
B) False True
C) False False
D) True False

8) What will be the output of the following code?

string=”Guess the output of this code”


print(string.split(‘t’))

A) ['Guess ', 'he ou', 'pu', ' of ', 'his code'] 1M


B) ['Guess t', 'he out', 'put', ' of t', 'his code']
C) ['Guess ', 'the ou', 't pu', 't of ', 'this code']
D) NameError

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 2/19
12/14/23, 4:42 PM Python Assessment-100%

9)

x= 5+(6>4)+6/3*5
print(x)

A) 16.0 1M
B) 8.0
C) 6.0
D) 24.0

10) Which of the following do not give any error?

a.
a=4
b=5
if(a>b):
print(‘a>b’)
elif(a<b and a==b):
print(‘a<=b’)
b.
a=4
b=5
if(a>b):
print(‘a>b’)
elif:
print(‘a<=b’)
c.
a=4
b=5
if(a>b):
print(‘a>b’)
elif(a<b):
print(‘a<b’)
else: print(‘a==b’)

A) a 1M
B) b
C) c
D) both a and b

11) .Which of the following code blocks give an error?

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 3/19
12/14/23, 4:42 PM Python Assessment-100%

a.
opt=2
if(opt==1):
print(‘Choosen first option’)
elif(opt==2):
print(“Choosen second option”)
elif(opt==3):
print(‘Choosen third option’)
b.
if(1): print(“If block”)
else: print(“Else block”)
c.
no=5
if(no%2==0):
print(‘Even Number’)
else(no%2==1):
print(‘Odd Number’)

A) a 1M
B) c
C) b and c
D) b

12) Which of the following gives the output as 3?

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 4/19
12/14/23, 4:42 PM Python Assessment-100%

a.
a=10
b=4
if(a&b):
print((a-b)/2)
else:
print(a-b/2)
b.
a=10
b=4
if(a^b):
print((a-b)/2)
else:
print(a-b/2)
c.
a=10
b=4
if(~a):
print(a-2*b+1)
else:
print(a-b/2)
d.
a=10
b=4
if(a-b):
print(a-2*(b+1))
else:
print(a-b/2)

A) a 1M
B) b
C) c
D) d

13) Which of the following do not give any error?

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 5/19
12/14/23, 4:42 PM Python Assessment-100%

a.
a=4
b=5
if(a>b):
print(‘a>b’)
elif(a<b and a==b):
print(‘a<=b’)
b.
a=4
b=5
if(a>b):
print(‘a>b’)
elif:
print(‘a<=b’)
c.
a=4
b=5
if(a>b):
print(‘a>b’)
elif(a<b):
print(‘a<b’)
else: print(‘a==b’)

A) a 1M
B) b
C) c
D) both a and b

14) What is the output of the following code?

for i in range(1,6,2):
if (i==4):
break
print(i,end=” “)

A) 1 3 1M
B) 1 2 3
C) 2 6
D) 1 3 5

15) Which of the following functions cannot be used to add an element to the list?
A) add() 1M
B) insert()
C) append()

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 6/19
12/14/23, 4:42 PM Python Assessment-100%

D) extend()

16) Which of the following is the extra property of frozen set? 1M


A) Can access values using index
B) Immutable
C) Have more number of bulti-in operations
D) All the above

17) Which of the following is correct code to create a dictionary comprehension? 1 M


A) dic={x*2 for x in range(1,6)}
B) dic={x:x*2 for x in range(1,6)}
C) dic=[x*2 for x in range(1,6)]
D) dic=[x:x*2 for x in range(1,6)]

18) Find the output of the following code?

set1={‘a’,’o’,’e’,’u’,’i’}
enm=enumerate(set1)
enm=enumerate(set1)
print(set(enm))

Ans 3

A) {‘a’,’e’,’i’,’o’,’u’} 1M
B) {{0, 'i'}, {2, 'a'}, {1, 'u'}, {3, 'o'}, {4, 'e'}}
C) {(0, 'i'), (2, 'a'), (1, 'u'), (3, 'o'), (4, 'e')}
D) <enumerate object at 0x0000018C2A10D280>

19) Find the output of the following code?

set1={3.5,’g’,6,3}
set2={‘h’,4,3,’y’}
set1.symmetric_difference(set2)

A) {3, 3.5, 4, 'h', 6, 'y', 'g'} 1M


B) {3.5, 4, 'h', 6, 'y', 'g'}
C) {3.5, 6, 'g'}
D) None of the above

20) Which of the following gives the out put as 3 if the dictionary is
dic={‘a’:{3:4,6:2},’t’:5,7:{1:3,9:1}}

A) dic[‘a’][1] 1M

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 7/19
12/14/23, 4:42 PM Python Assessment-100%

B) dic[7][1]
C) dic[0][1]
D) dic[7][0]

21) What will be the output of bellow code.

A) 2 1M
B) 3
C) 4
D) 1

22) What is the correct syntax to pass variable length arguments?

A) Asterisk followed by the underscore and the variable name 1M


B) Asterisk followed by the variable name
C) Asterisk followed by the variable name and square brackets
D) Variable name followed by the square barckets

23) File: greet.py


Code

>>> def say_hello(name):


>>> print(f”Hello {name}.”)

File: main.py
Code
>>> import greet
>>> greet.say_hello(“William”)

A) Hello William. 1M
B) Hello {name}.
C) SyntaxError
D) Program compiles but doesn’t print anything

24)

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 8/19
12/14/23, 4:42 PM Python Assessment-100%

minions.py
Code
>>> def fav_food():
>>> print(“Bananas”)
>>> if __name__ == “__main__”:
>>> fav_food()

File: run_minions.py
Code
>>> import minions
>>> minions.fav_food()

A) String “Bananas” is printed twice 1M


B) String “Bananas” is printed once
C) String “Bananas” is printed thrice
D) SyntaxError

25)

File: Cars.py
Code
>>> def car():
>>> print(‘A car’)

File: main.py
Code
>>> from Cars import car
>>> def car():
>>> print(“Not a car”)
>>> car()

A) Not a car 1M
B) a car
C) Runtime Error
D) Compile-time Error

26) Find the output of the following code?

def fun(x,y=0,z):
print(x-y+z)
fun(1,23)

A) 24 1M
https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 9/19
12/14/23, 4:42 PM Python Assessment-100%

B) -22
C) 23
D) SyntaxError

27)

>>> class Fruit:


>>> pass
>>> print(Fruit.__name__)

A) class 1M
B) __main__
C) AttributeError
D) Fruit

28) What keyword is used to delete an object in Python?

A) remove 1M
B) delete
C) pop
D) del

29) How many parameters do non-parameterized constructors contain?

A) 0 1M
B) 1
C) 2
D) More than two

30) .What is the output of the below code?


Code

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 10/19
12/14/23, 4:42 PM Python Assessment-100%

>>> class Multiply:

>>> def __init__(self, x):


>>> self.x = x

>>> def __mul__(self, other):


>>> return f”{self.x} X {other.x} = {self.x * other.x}”

>>> a = Multiply(5)
>>> b = Multiply(10)
>>> print(a * b)

A) 50 1M
B) 5 X 10 = 50
C) a X b = a * b
D) Both A and B

31) What is the output of the below code?


Code

>>> class Class1:


>>> def __init__(self, n):
>>> self.n = n
>>> def __add__(self, other):
>>> return self.n – other.n
>>> a = Class1(4)
>>> b = Class1(1)
>>> print(a + b)

A) SyntaxError 1M
B) 5
C) 4
D) 3

32) What is the output of the below code?


Code

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 11/19
12/14/23, 4:42 PM Python Assessment-100%

>>> class Car:

>>> def __init__(self, speed):


>>> self.speed = speed
>>> def __gt__(self, other):
>>> if self.speed > other.speed:
>>> return “Car1 is faster than Car2”
>>> else:
>>> return “Car2 is faster than Car1”
>>> car1 = Car(130)
>>> car2 = Car(250)
>>> print(car1 > car2)

A) Car1 is faster than Car2 1M


B) Car2 is faster than Car1
C) True
D) False

33)

.class SomeClass:
>>> def __init__(self):
>>> self.attr1 = “Hello World”
>>> obj = SomeClass()
>>> setattr(obj, ‘attr2′, getattr(obj,’attr1’))
>>> print(obj.attr2)

A) getattr(obj,'attr1') 1M
B) Hello
C) AttributeError
D) Hello World

34) .What is the output of the below code?


Code

>>> class Apple:


>>> def __init__(self, apples):
>>> self.apples = apples

>>> a1 = Apple(100)
>>> a2 = Apple(25)
>>> a3 = Apple(a1.apples % (Apple(10).apples + a2.apples))
>>> print(a3.apples)

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 12/19
12/14/23, 4:42 PM Python Assessment-100%

A) 28 1M
B) 25
C) 30
D) 35

35) . What is the output of the below code?


Code

>>> class Reeta:


>>> name = “Reeta”
>>> blood_group = “B Positive”
>>> class Priyanka(Reeta):
>>> name = “Priyanka”
>>> person = Priyanka()
>>> print(person.name, “-“, person.blood_group)

A) Priyanka – B Positive 1M
B) Reeta – B Positive
C) Runtime error
D) Compile-time error

36) .Find the output of the below code.


try:

n=0

assert n>0

raise

except:

print(“Exception”)

A) AssertionError 1M
B) AssertionErrorException
C) Exception
D) None of the above

37) from abc import ABC, abstractmethod


>>> class AbstractClass(ABC):

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 13/19
12/14/23, 4:42 PM Python Assessment-100%

>>> @abstractmethod

>>> def some_method():

>>> pass

>>> ac = AbstractClass()

>>> print(ac)

A) TypeError 0M
B) ac
C) AbstractClass
D) object

38) What is the output of the below code?

Code
>>> class Sum:
>>> def __init__(self, n):
>>> self.n = n
>>> num = 0
>>> if isinstance(int, object):
>>> num += 1
>>> if isinstance(num, object):
>>> num += 4
>>> if isinstance(Sum, object):
>>> num += 6
>>> N = Sum(num)
>>> if isinstance(N, (object, Sum)):
>>> num += 2
>>> print(N.n + num)

A) 20 1M
B) 24
C) 26
D) 14

39) What is the output of the below code?


Code

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 14/19
12/14/23, 4:42 PM Python Assessment-100%

>>> class Square:

>>> def __init__(self, side):


>>> self.side = side
>>> self.area = side*side

>>> s1 = Square(Square(Square(2).side).area)
>>> print(s1.area)

A) syntaxError 1M
B) TypeError
C) 32
D) 16

40) What is the output of the below code?


Code

>>> class Phone:


>>> count = 0

>>> def __init__(self, brand, model, os):


>>> self.brand = brand
>>> self.model = model
>>> self.os = os
>>> Phone.count += 1

>>> iPhone = Phone(“Apple”, 11, “iOS”)


>>> one_plus = Phone(“One Plus”, “Nord”, “Android”)
>>> iPhone.model = f”{one_plus.model}{Phone.count}”
>>> print(iPhone.model)

A) 11 1M
B) Nord
C) Nord0
D) Nord2

41) What is the output of the below code?

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 15/19
12/14/23, 4:42 PM Python Assessment-100%

Code
>>> class SuperClass:
>>> __hello = “Hello”

>>> class SubClass(SuperClass):


>>> pass
>>> print(SuperClass.__hello)

A) Hello 1M
B) NameError
C) AttributeError
D) None of the above

42) What is the output of the below code?

Code
>>> class Audio:
>>> def use(self):
>>> print(“To listen”)

>>> class Video:

>>> def use(self):


>>> print(“To see”)
>>> class Movie(Audio, Video):
>>> def use(self):
>>> super().use()
>>> m1 = Movie()
>>> m1.use()

A) To listen 1M
B) To see
C) Both A and B
D) AttributeError

43) What is the output of the below code?

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 16/19
12/14/23, 4:42 PM Python Assessment-100%

Code
>>> class Basket:
>>> fruits = 0
>>> @classmethod
>>> def add_fruit(cls):
>>> cls.fruits += 1
>>> basket1 = Basket()
>>> basket1.add_fruit()
>>> basket1.add_fruit()
>>> basket2 = Basket()
>>> print(basket2.fruits)

A) 2 1M
B) 1
C) Error
D) 3

44) What is the output of the below code?


Code

>>> class Addition:


>>> def __init__(self, num):
>>> self.num = num

>>> def __add__(self, other):


>>> return self.num – other.num

>>> num1 = Addition(10)


>>> num2 = Addition(3)
>>> print(num1 + num2)

A) 13 1M
B) -7
C) 7
D) -13

45) Comments in Python begin with?


A) ** 1M
B) <!-- -->
C) #
https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 17/19
12/14/23, 4:42 PM Python Assessment-100%

D) '''

46) Which of the following is False regarding loops in Python?


A) Loops are used to perform certain tasks repeatedly. 1M
B) While loop is used when multiple statements are to executed repeatedly
until the given condition becomes False
C) While loop is used when multiple statements are to executed repeatedly
until the given condition becomes True.
D) for loop can be used to iterate through the elements of lists.

47) Which of the following is True regarding loops in Python?


A) Loops should be ended with keyword "end". 1M
B) No loop can be used to iterate through the elements of strings.
C) Keyword "break" can be used to bring control out of the current loop.
D) Keyword "continue" is used to continue with the remaining statements inside
the loop.

48) To read two characters from a file object f, we use ____________


A) f.read() 1M
B) f.read(2)
C) f.read(a,b)
D) f.read(0,2)

49) Which function returns a list containing all matches?


A) find() 1M
B) findall()
C) match()
D) search()

50) What will be the output of the following code?


list = [

['a', 'b', ['c', 10]],

['p', [1,2,3], 'q', 'r'],

[7,8,9,['x', 'y', 'z']]

print(list[1][1][2], list[0][2][0], list[2][3][1])

A) 2 10 x 1M

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 18/19
12/14/23, 4:42 PM Python Assessment-100%

B) 3 c y
C) 1 10 y
D) 2 c x

https://wingz.itvedant.com/index.php/assignment-test-student/exam-view-topic?id=8775 19/19

You might also like