NEW
Font size
WorksheetsPYTHON_Random Module
Total questions: 50
Worksheet time: 2hrs 40mins
_____ represents an entity in the real world with its identity and behaviour.
A method
An object
A class
An operator
What type of inheritance is illustrated in the following Python code?
class A():
pass
class B():
pass
class C(A,B):
pass
Multi-level inheritance
Multiple inheritance
Hierarchical inheritance
Single-level inheritance
What will be the output of the following Python code?
class A:
def __init__(self):
self._x = 5
class B(A):
def display(self):
print(self._x)
def main():
obj = B()
obj.display()
main()
Error, invalid syntax for object declaration
Nothing is printed
5
Error, private class member can’t be accessed in a subclass
What will be the output of the following Python code?
def say(message, times = 1):
print(message * times)
say('Hello')
say('World', 5)
Hello
WorldWorldWorldWorldWorld
Hello
World 5
Hello
World,World,World,World,World
Hello
HelloHelloHelloHelloHello
What will be the output of the following Python code?
def func(a, b=5, c=10):
print('a is', a, 'and b is', b, 'and c is', c)
func(3, 7)
func(25, c = 24)
func(c = 50, a = 100)
a is 7 and b is 3 and c is 10
a is 25 and b is 5 and c is 24
a is 5 and b is 100 and c is 50
a is 3 and b is 7 and c is 10
a is 5 and b is 25 and c is 24
a is 50 and b is 100 and c is 5
a is 3 and b is 7 and c is 10
a is 25 and b is 5 and c is 24
a is 100 and b is 5 and c is 50
Error
What will be the output of the following Python code?
a=10
b=20
def change():
global b
a=45
b=56
change()
print(a)
print(b)
10
56
45
56
10
20
Error
What will be the output of the following Python code?
class A:
def test1(self):
print(" test of A called ")
class B(A):
def test(self):
print(" test of B called ")
class C(A):
def test(self):
print(" test of C called ")
class D(B,C):
def test2(self):
print(" test of D called ")
obj=D()
obj.test()
test of B called
test of C called
test of C called
test of B called
test of B called
Error, both the classes from which D derives has same method test()
Exceptions
try:
n = int(input("How old are you? "))
percent = round(n*100/80, 1)
print("You've gone through", percent, "% of your life!")
except ValueError:
print("Oops, must enter a number.")
except ZeroDivisionError:
print("Division by zero.")
except:
print("Something went very wrong.")
If the user enters "0" in the code above what does the program do?
prints "You've gone through 0.0 % of your life!"
prints "Division by zero."
Suppose B is a subclass of A, to invoke the __init__ method in A from B, what is the line of code you should write?
A.__init__(self)
B.__init__(self)
A.__init__(B)
B.__init__(A)
Error because class B inherits A but variable x isn’t inherited
0 0
0 1
Error, the syntax of the invoking method is wrong
Error, the syntax of the invoking method is wrong
The program runs fine but nothing is printed
1 0
1 2
Error as age isn’t defined
True
False
7
Old
New
error
Nothing is printed
12
52
13
60
test of B called
test of C called
test of C called
test of B called
test of B called
test of B called
people = ["John", "Rob", "Bob"]
print (people[4])
what would this result be?
What does __init__ do?
Constructs the instance
Initialize the instance values
Calls the Super class
Creates a circle
What is the process of using a function for more than one purpose that allows the use of different internal structures of the object by keeping the same external interface?
Inheritance
Polymorphism
Abstraction
Encapsulation
What is the process in which objects of one class can link and share some common properties from the objects of another class?
Abstraction
Inheritance
Polymorphism
Encapsulation
Which of the following is correct with respect to the OOP concept in Python?
Objects are real-world entities while classes are not real.
Classes are real-world entities while objects are not real.
Both objects and classes are real-world entities.
Both objects and classes are not real.
In which approach data hiding is not possible ?
POP
OOP
How many Access Specifiers are available ?
1
2
3
In which approach all the variable are Global Variable ?
POP
OOP
In POP who can communicate with each other ?
Object
Procedure
What is the main advantage for OOP ?
Data Hiding
Code Reusability
POP follows
Top-Down Approach
Bottom-Up Approach
OOP follows
Top-Down Approach
Bottom-Up Approach
The name given to a procedure or function residing within a class.
method
attribute
modifier
parameter
What does an object consist of?
Methods
Attributes
Methods and Attributes
Procedures
Variables
It is a person who writes, develops, and debugs the program.
Web developer
Computer technician
IT Expert
Programmer
It refers to the third step in creating program.
Code the program.
Define the scope of the problem.
Test and Debug the program.
Creating a visual interface.
A block within a block is called ________block.
Nested
Control
Compressed
Called
What is the output of the following program:
import re
sentence = 'horses are fast'
regex = re.compile('(?P<animal>\w+) (?P<verb>\w+) (?P<adjective>\w+)')
matched = re.search(regex, sentence)
print(matched.groupdict())
{‘animal’: ‘horses’, ‘verb’: ‘are’, ‘adjective’: ‘fast’}
(‘horses’, ‘are’, ‘fast’)
‘horses are fast’
‘are’
7. How many types of functions available in Python?
3
2
1
4
random.randrange(6)
0,1,2,3,4,5,6
1,2,3,4,5,6
0,1,2,3,4,5
1,2,3,4,5
random.uniform() requires two parameters
True
False
random.random() generates a floating point number between _____ and ______
1 and 2
1 and 0
0 and 1
0 and 10
docstrings
single quoted comments
double quoted comments
triple quoted comments
hash tagged comments
Write the output of the following code :
import random
for i in range(random.randint(2,2)):
print(i)
0
1
1
2
0
1
2
Generate different number
Write the output of the following code :
import random
for i in range(random.randint(2,3)):
print("A")
A
A
A
A
A
A
A
OR
A
A
A
ERROR
What is the minimum and maximum value of 'A' in the following statement..
import random
A=random.randint(2,30)
print(A)
3 and 30
2and 30
2 and 29
Write the output of the following code :
import random
A=random.randrange(20)
print(A)
Any number between 0 to 19 (including both)
Any number between 0 to 20 (including both)
Any number between 1 to 20 (including both)
Write the output of the following code :
import random
print(int(random.random()))
Any random number less than 1 and greater than 0
Always generate 0
Always generate 1
Shows Error
Which of the following subject will never printed in following code?
import random
L=["English","Hindi","Math","Science","SST","CS","IP"]
for i in range(random.randint(1,6)):
print(L[i])
CS and IP both
English
IP
English and Hindi both
Which of the following method is not included in random module?
Shuffle( )
randrange( )
randomrange( )
uniform( )
A = random.______([1,2,3,4,5])
Value of A can be 1 to 5(including both)
shuffle
choice
uniform
none of these
