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.
import tempConversion print(tempConversion.to_centigrade(10)) # prefix is used in function call from tempConversion import to_centigrade print(to_centigrade(1)) # no prefix needed
in program one the checkMain() is import as import Allchecks in program two the checkMain() is import as from Allchecks import checkMain()
# """ 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)
(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
(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.
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.
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#
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.
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
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.
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
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.
(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()
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
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 TutorIn 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
You cannot copy content of this page