Using Python Libraries || Type B || Sumita Arora || Class 12 || Computer science || Information practices || Solution || 




Q1 = Create module tmpConvenion.py as given in Fig 4.2 in the chapter.
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?






Q2 = A function checkMain() defined in module Allchecks.py is being used in two different programs. In program 1 as

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?






Q3 = Given below is semi-complete code of module basic.py:

#
"""___________"""

def square (x):
    """_________"""
    return mul(x, x):
___mul(x,y) :

"""___________"""

return x*y

def div(x, y) :
    """________"""
    return float(x)/y

____def fdiv(x, y)____
    """_______"""
    ________x//y
    

def floordiv(x, y)____
_______fdiv(x,y)

Complete the code. Save as a module





    


Q4 = After importing the above module some of its functions are executed as per following statements. Find errors, if any

a) square(print 3)
b) basic.div()
c) basic.floordiv(7.0,7)
d) div(100, 0)
e) basic.mul(3,5)
f) print (basic.square(3.5))
g) z = basic.div(13,3)





Q5 = Import the above module basics.py and write statements for the following:

(a) Compute square of 19.23

(b) Compute floor division of 1000.01 with 100.23

(c) Compute product of 3, 4 and 5 (Hint: use a function multiple times)

(d) What is the difference between basics.div(100,0 ) and basics.div(0, 100)?







Q6 = 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.





Q7 = 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#






Q8 = Consider the following code:

import random

print (int( 20 + random.random()*5), end =" ")
print (int( 20+ random.random()*5), end =" ")
print (int(20 + random.random()*5), end = " ")
print (int( 20 + random.random()*5))

Find the suggested output options (i) to (iv). Also, write the least value and highest value that can be generated.

(i) 20 22 24 25
(ii) 22 23 24 25
(iii) 23 24 23 24
(iv) 21 21 21 21




Q9 = Consider the following code:

import random

print (100 + random.randint(5, 10), end = ' ')

print (100 + random.randint(5, 10), end = ' ')

print (100 + random.randint(5, 10), end = ' ')

print (100 + random.randint(5, 10))


Find the suggested output options (i) to (iv). Also, write the least value and highest value that can be generated.

(i) 102 105 104 105
(ii) 110 103 104 105
(iii) 105 107 105 110
(w) 110 105 105 110






Q10 = Consider the following package

music/        Top level package
|
|----__inti__.py    
|----formats/    sub package for file format
|    |
|    |--- __inti__.py
|    |---wavread.py
|    |---wavwrite.py
|
|----effects/    sub package for sound effects
|    |
|    |--- __inti__.py
|    |---echo.py
|    |---surround.py
|    |---reverse.py
|
|----filters/   sub package for filters
    |
    |--- __inti__.py
    |---equlizer.py
    |---vocoder.py
    |---karaoke.py

Each of the above modules contain functions play(), writefile() and readfile().

(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. 




Q11 = What are the possible outcome(s) executed from the following code ? Also specify the maximum and minimum values that can be assigned to variable PICKER.

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()


(i)
DELHIDELHI
MUMBAIMUMBAI
CHENNAICHENNAI
KOLKATAKOLKATA

(ii)
DELHI
DELHIMUMBAI
DELHIMUMBAICHENNAI

(iii)
DELHI
MUMBAI
CHENNAI
KOLKATA

(iv)
DELHI
MUMBAIMUMBAI
KOLKATAKOLKATAKOLKATA



Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post