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()
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()
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)] |
[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
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
def func( a, b = 5, c = 10):
poly = 2 * a ** 2 - 5 * b + c
print("With values", a, b, c)
print(poly)
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.
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.
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.
not all que and ans are there
ReplyDeleteWe have not uploaded theory questions but don't worry we are working on it.
DeleteI appreciate your hard work and I am thankful to you but please can you upload the answers for practical 3.1
ReplyDeleteWelcome : ) Practical question and answer will upload very soon.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )