Chapter 4 - Type B - Application Based Questions
Chapter 4 - Type B - Application Based Questions
If you invoke the module with two different types of import statement, how would the function call
statement for imported module’s functions be affected?
Answer
If we use ‘import’ command then we will able to call all function which is present in file ‘tmpConvenion.py’
For example:
import tmpConvenion
2. A function checkMain() defined in module Allchecks.py is being used in two different programs. In
program 1 as
Allchecks.checkMain(3, ‘A’)
and in program 2 as
checkMain(4, ‘Z’)
Why are these two-function call statement different from one another when the function being invoked
is just the same?
Answer
Program 1 give result like
import Allchecks
Allchecks.checkMain(3, ‘A’)
While Program 2 call checkMain(4, ‘Z’) after running the module Allchecks.py
3. Given below is semi-complete code of module basic.py: Complete the code. Save as a module
# """___________"""
def square (x):
"""_________"""
return mul(x, x):
___mul(x,y) :"""___________"""
return x*y
def div(x, y) :
"""________"""
1
return float(x)/y
____def fdiv(x, y)____
"""_______"""
________x//y
def floordiv(x, y)____
_______fdiv(x,y)
Answer
4. After importing the above module some of its functions are executed as per following statements.
Find errors, if any
2
5. Import the above module basics.py and write statements for the following:
6. Suppose that after we import the random module, we define the following function called diff in a
Python session:
import random
def diff():
x = random.random() - random.random()
return(x)
What would be the result you now evaluate?
y = diff ()
print(y)
At the Python prompt? Give reasons for your answer.
Answer
It will give output subtracted number which is generated by random() function. Because random() function
generate number between 0.0 <= N < 1.0
3
7. What are the possible outcome(s) executed from the following code? Also specify the maximum and
minimum values that can be assigned to variable NUMBER.
Import random
STRING="CBSEONLINE"
NUMBER = random.randint (0, 3)
N=9
while STRING[N] != "L":
print (STRING[N] + STRING[NUMBER] + "#", end = " ")
NUMBER = NUMBER +1
N=N-1
(i) ES#NE#IO# (ii)LE#NO#ON# (iii)NS#IE#LO# (iv)EC#NB#IS#
Answer
Outcomes are (i)Maximum value of NUMBER is 6.
Minimum value of NUMBER is 3.Because Minimum value of NUMBER from random.randint (0, 3) is 0 and
while loop will run only 3 times. So, Minimum value of NUMBER is 3.Maximum value of NUMBER from
random.randint (0, 3) is 3 and while loop will run only 3 times. So, Maximum value NUMBER is 6.
Output of Code :-
EC# NB# IS# 3
EB# NS# IE# 4
ES# NE# IO# 5
EE# NO# IN# 6
Answer
Option (iii) & (iv) will generate only.
Highest value is 110
Least value is 105
Each of the above modules contain functions play(), writefile() and readfile().
5
(a) If the module wavwrite() is imported using command import music.formats.wavwrite. How will you
invoke its writefile() function? Write command for it.
(b) If the module wavwrite() is imported using command from music.formats import wavwrite. How will
you invoke its writefile() function? Write command for it.
Answer
(a)import music.formats.wavwrite
music.formats.wavwrite.writefile()
import random
PICK = random.randint (0, 3)
CITY = ["DELHI", "MUMBAI", "CHENNAI", "KOLKATA"]
for I in CITY :
for j in range(1, PICK):
print(I, end =" ")
print()
Answer
Option (i) & (iii) will generate only.
Highest value is 3
Least value is 0