# [Type B] Chapter– 4 Class 12 CS – Sumita Arora Assignment | Q/A

Here is class 12 computer science Unit 4 [Type B] solutions for Sumita Arora back exercise assignment. Below includes both textual and video solutions wherever required. View all the answers in assignment for chapter 4 and for all chapters here.

Watch all tutorials for chapter 4: Python Revision Tour.

Q1: Create module tempConversion.py as given in Fig 4.2 in the chapter.

### Solution:

```import tempConversion
print(tempConversion.to_centigrade(10)) # prefix is used in function call

Q2: A function checkMain() defined in a 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’)
```in program one the checkMain() is import as
import Allchecks

in program two the checkMain() is import as
from Allchecks  import checkMain()```
Q3: Given below is the semi-complete code of a module basic.py:

### Solution:

```#
""" Module for basic calculations"""

def square(x):
"""Returns square of a number"""
return x**2

def mul(x, y):
"""Returns product of two number"""
return x*y

def div(x, y):
"""Returns division of two number"""
return x/y

def fdiv(x, y):
"""Returns division of two number"""
return x//y

def floordiv(x, y):
return fdiv(x,y)```

Q4: After importing the above module, some of its functions are executed as per the 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 = basicdiv(13, 3)
```(a) function will accept a number as parameter not another function as argument. Hence, will occur.

(b) function need two argument but none of the given. Hence, error will occur.

(c) No error

(d) Division by zero will raise an error of not possible calculation.

(e) No error

(f) No error

(g) no error```
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 with100.23
(c) compute product of 3, 4 and 5
(d) What is the difference between basics.div(100, 0) and basics.div(0, 100)?
```(a) basics.square(19.23)
(b) basics.floordiv(1000.1, 100.23)
(c) basics.mul(5, basics.mul(3,4))
(d) basics.div(100, 0) will cause error as divisible by zero is not possible and second case will execute.```
Q6: Suppose that after .we import the random module, we define the following function called diff in a Python session:
```def diff():
x = random.random() - random.random()
return x

what would be the result is you now evaluate
y = diff()
print(y)
at python prompt?```

Solution:

`The output will be between -1 and 1 because random.random() give value between 0 and 1.`
Q7: What are the possible outcome(s) executed from the following code? Also, specify the maximum and minimum values that can be assigned to the variable NUMBER.
```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#```

Solution:

```The possible outcome of the above code will possible the two case
(i) ES#NE#IO# , (iv) EC#NB#IS# as the while code will run three time and will choose according to that and N will have (9, 8, 7) only.```
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)

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

Solution:

```So, the possible output of the above code will be (iii) 23 24 23 24 , (iv) 21 21 21 21

As random.random() will have value minimum and maximum 0 and 1 respectively.
Hence, the minimum value of above code will be 20 and maximum will be 25.```
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 from options.

(i) 102 105 104 105 (ii) 110 103 104 105 (iii) 105 107 105 110 (iv) 110 105 105 110```

Solution:

```So, the possible output of the above code will be (iii) 105 107 105 110 (iv) 110 105 105 110
As random.randint(5, 10) will have value minimum and maximum 5 and 10 respectively. Hence, the minimum value of above code will be 105 and maximum will be 110.```
Q10: Consider the following package:
```(a) in this case to invoke writefile() the command will be
music.formats.wavwrite.writefile()

(b)in this case to invoke writefile() the command will be
wavwrite.writefile()```
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)                           (ii)
DELHIDELHI                     DELHI
MUMBAIMUMBAI                   DELHIMUMBAI
CHENNAICHENNAI                 DELHIMUMBAICHENNAI
K0LKATAKOLKATA

(iii)                        (iv)
DELHI                        DELHI
MUMBAI                       MUMBAIMUMBAI
CHENNAI                      KOLKATAKOLKATAKOLKATA
KOLKATA
```

Solution:

```The possible outcome can be (i) and (iv).
As the minimum value is 0 and maximum is 3. When range is 1 the pick will be 0 and nothing will be print same as pic is 1 but when it became 2 everything will be printed and for 3 everything will be printed twice.```

Clear Doubts with Computer Tutor
In case you’re facing problems in understanding concepts, writing programs, solving questions, want to learn fun facts | tips | tricks or absolutely anything around computer science, feel free to join CTs learner-teacher community: students.computertutor.in