Working with Functions Sumita Arora Practical Solution Class 12 Computer science



P.I.P :- 3.1




Q2. There are some function call statements given below. Pick the function call statements for the
function definitions given in question 1:
(a) subtract(3, 5)
(b) cube2(7, x)
(c) sub(5, 3)
(d) cubel(a, a, a)
(e) greetings('hello')
(f) sub2(8,9)
(g) greeting()
(h) sub1(x, y)
(i) cube1(x)
(j) sub2(p, q)
(k) sub1(5,3)
(l) cube2(num)
(m) sub1(8,9,10)
(n) cube(7)
Function call statements for sub1()
Function call statements for cube1()
Function call statements for cube2()
Function call statements for greeting()



Q3. If you carefully observe the function definitions of question1, you'll find functions sub1() and cube2() are basically doing the same thing - calculating difference between two values. Logically they are doing same thing but technically these are different. What is the difference?



P.I.P :- 3.2



 
(a) Function header
(b) Number & name of arguments
(c) Number of statements in function body
(d) Number of statements in main program (__main__)
(e) Function call statement
(f) Parameters' name
(g) Arguments' name
(h) Flow of execution[mention the execution order of statements e.g., main.1 means main program's statementl executed and fn.1 means function's statementl executed. A sample order could be main.1, fn.1, main.2 etc. (This flow of execution is not for above code : p)]


Q2. Consider the following function definitions. Write appropriate function call statements for these.

[Hint: Be careful about which function calls should be part of some expression or statement]

 
S.No. Function Definition Function Call
(a) def sumof3Multiplesi(n):
    s = n * + 1 + n * 2 + n * 3
    return s
(b) def sumof3Multiples2 (n) :
    s = n + 1 + n * 2 + n * 3
    print(s)
(c) def areaOfSquare(a) :
    return a * a
(d) def areaOfRectangle (a, b) :
    return a * b
(e) def perimeterCircle(r):
    return (2 * 3.1459 * r)
(f) def perimeterRectangle(l, b) :
    return 2 * (l + b)
(g) def Quote():
    print("\t Quote of the Day")
    print("Act Without Expectaton!")
    print("\t-Lao Tzu")
(h) def poly(x, y, z):
    s = x ** 3 + y ** 2 + z
    return s


Q3. For the function definitions given in question 2 here, write main program segment for function definitions numbered given below:
S.No. Function Definition Main Program
(a) def sumof3Multiplesi(n):
    s = n * 1 + n * 2 + n * 3
    return s
(b) def sumof3Multiples2( n ) :
    s = n * 1 + n * 2 + n * 3
    print(s)
(c) def Quote():
    print("\t Quote of the Day")
    print("Act Without Expectation!")
    print("\t-Lao Tzu")
(d) def poly(x, y, z):
    s = x ** 3 + y ** 2 + z
    return s





Q5. Write a program chkOdd() that takes one argument and report if the argument is odd or not.



P.I.P :- 3 .3



Q2. What will be the output produced by above program (given in question 1)?











Q8. Write a function that takes a character and returns true if it is a vowel, false otherwise.


Q9. Write a program that passes value to  a function mersenne() and the function return nth mersenne number.


Q10. Write a void function that receives a 4-digit number and calculate the sum of the square of first 2 digits number and last digits number.


Q11. Write a function that takes one argument and report if the argument is prime or not. Write a program that invokes this function.



P.I.P :- 3.4





Q3. Consider following program code.
1. def myFunc(1, v):
2. l[0] += 2
3. v += 2
4. N = [2, 3, 4]
5. l = N
6. l.append(7)
7. print(l, v)
8. return
9. #__main__
10. list1 = [1]
11. var1 = 1
12. print("Values/variables before function call:", list1, var1)
13. myFunc(list1, var1)
14. print("Values/variables after function call: ", list1, var1)
(i) Identify flow of execution in the above program
(ii) What will be the output of above program?
(iii) What is reason of this output?
(iv) Try making memory environment(s) for above program.

4 Comments

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

  1. not all que and ans are there

    ReplyDelete
    Replies
    1. We have not uploaded theory questions but don't worry we are working on it.

      Delete
  2. I appreciate your hard work and I am thankful to you but please can you upload the answers for practical 3.1

    ReplyDelete
    Replies
    1. Welcome : ) Practical question and answer will upload very soon.

      Delete

Post a Comment

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

Previous Post Next Post