You are on page 1of 8
: sisson Fencton beer et proce onc cal remanneggy arene y Pomme = Fantom Bo xen Man pre yes 1. def power(b, 9) TE A local variable having the same name as that of 2 global variable. hides the function, |OTE © Anewers for OTOs are given at the end of the book. ‘Solved Problem 1 What i the significance of having fonctions in a program ? Sofstion. Creating functions in programs is very useful and used when needed in other programs. the program code given bel, identify the parts mentioned below ef processtumber(x): x=72 return x+3 y=58 processnunber(y) body, main ee on heer, anction call arguments, parameters function ‘solution. @ eee eaeessorst 2S. 0 eS eee 5 ee ee ; yon cde astra 4 global ota celal 1a oo ble and global variable are as iin | evar is variable wt ones A Tris accessible throughout the Solution. The reson for unelected changes inthe main program is that although both aiuin program aed sei) have variables trthsame names‘ x andy, but tei scopes arent shownin the adjacent igure print(res) Solution Global names 15 ind en def caln(): flobal a anis b=20 print(a) 4 the above program will be able to swap the values of variables through sw ee? Passing parameter is redundant) COMPUTER SciNC 165, lowing code? Compare and comment on thefllowing to return statements ‘The return statement is optional ONLY WHEN the function i vid or we can say that when the function does not return a value. A function that returns a value, must have atleast one return statement, ‘snot returning any value, rather it returns the contol to caller along with empty value None. And. the statement return val returning the control to caller alng withthe vale contained in variables Ta Weal cio it ua os ge eee Suton ‘ef getones(oun): ‘return the oe onesbigit «nun return onesosgit kites fncton tt ries en ela aera 7 ia, inary ant exec puns of the integer nu Please recall hat bin() and hex) donot return um cquivalent numbers in binary and hexadecimal number spe of variables? How can you acess a glbal variable inside TCBSE Sample Pape 2019-29] COMPUTER ScitNCE yp co Find Total for in args (1, meer #3) tion calls 2 a eet reat ew emo fe Une erg your reference. "| 1 af 2 a + 5 ‘ 7 ‘ 3 ones Sse elceeret”) a print(result) fonction return? ‘5. What wil be the output of following programs ? 0 nme def mya): return print oun) pri(ofurt)) print(nm) mane ef myfunc(): 1469 1 integer and prints the number that follows ater it. Call te flow of execution fr both the Daw a bt s 6 a 2 %. w 4, 12, print(sum(a, b, c,4), Length(), mean(a, b, c, d)) a iment and calculates cube for it The function does not 18. Draw flow of execution for above program, i eee to the function in function call, the function should 1. Inthe following code, which variables are in the same scope ? et finest): be able to print three numbers randomly. string arguments and checks whether they are same-length strings ess false). (ceturns True in thi ee ll ll 152 6. ba . Write a program that generates a series using a function which takes first and last values of COMPUTER SCIENCE wiry . PTH, Write a function namely nthRoot( ) that receives two parameters x and n and returns nth 1 TOot Oe xm, The default value of n is 2. _ Write a function that takes a number and then returns a randomly generated number havin 8 digits (not starting with zero) e.g., if nis 2 then function can randomly return a number 10-99 Say, etc. are not valid two digit numbers. but Write a function that takes two numbers and returns the number that has minimum one’s [For example, if numbers passed are 491 and 278, then the function wi minimum one’s digit out of two given numbers (491’s 1 is < 278's 8 digit return 491 because it has ot and then generates four terms that are equidistant e.g., if two numbers passed are 1 and 7 nal returns 1357.

You might also like