Here are PRIP 3.2 Sumita Arora Solutions for class 12 Computer Science. To view chapter 3 conceptual videos, visit here.
To view Sumita Arora solutions for all chapters, visit here.
Q.1: Identify the mentioned parts from the code given below
1. def lastDigitCube(n):
2. d = n%10
3. c = d**3
4. return c
6. number = int(input("Enter a number :")
7. cube = lastDigitCube(number)
8. print("The cube of its last digit is", cube)
2. d = n%10
3. c = d**3
4. return c
6. number = int(input("Enter a number :")
7. cube = lastDigitCube(number)
8. print("The cube of its last digit is", cube)
Answer:
(a) | Function Header | def lastDigitCube(n): |
(b) | Number and name of arguments | Number:1, name: n |
(c) | Number of statements in function body | Number: 2, 3, 4 |
(d) | Number of statements in main program | Number: 6, 7, 8 |
(e) | Function call statement | Number: 7 |
(f) | Parameter’s name | n |
(g) | Argument’s name | number |
(h) | Flow of execution mention the execution order of statements e.g. main.1 means main program’s statement1 executed and fn.1 means function statement1 executed A sample order could be main1. fn.1, main.2 etc. (This flow of execution is not for above code:p) | 1 -> 6 -> 7 -> 1 -> 2 -> 3 -> 4 -> 8 |
Q.2: 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]
Answer:
S. No. | Function Definition | Function Call |
(a) | def sumof3Multiples1(n): | N = 10 |
(b) | def sumof3Multiples2(n): | N = 10 |
(c) | def areaOfSquare(a): | S = 10 |
(d) | def areaOfRectangle(a,b): | A = 10 |
(e) | def perimeterCircle(r): | R = 10 |
(f) | def perimeterRectangle( l, b): | length= 20 |
(g) | def Quote(): | Quotes() |
(h) | def poly(x, y, z): | S = poly(X, Y, Z) print(S) |
Q.3: For the function definitions given in question 2 here, write a main program statement for function definitions numbered given below:
Answer:
S. No. | Function Definition | Main program |
(a) | def sumof3Multiples1(n): | if(__name__==”__main__”): |
(b) | def sumof3Multiples2(n): | If(__name__==”__main__”): |
(c) | def Quote(): | If(__name__==”__main__”): |
(d) | def poly(x, y, z): | if(__name__==”__main__”): |
Q.4: Define a Python function called absolute that takes one parameter (x) and returns the absolute value of x, i.e. as shown below: |x| = (x if x >= 0 , -x otherwise)
Don’t forget to use a return statement at the end.
Also, write the code that will demonstrate math absolute function by computing and print the absolute value of
6 and -3. Be sure to pay attention to proper indentation
Answer:
Code:
def absolute(x):
if x < 0:
x = abs(x)
return x
if(__name__ == '__main__'):
a = absolute(6)
b = absolute(-3)
print("absolute value of 6: {}".format(a))
print("absolute value of -3: {}".format(b))
Output:
absolute value of 6: 6
absolute value of -3: 3
Q.5: Write a program with a function chkOdd() that takes one argument (a positive integer) and reports if the argument is odd or not.
Answer:
Code:
def chkOdd(num):
if(num % 2 == 1):
return True
return False
if(__name__ == '__main__'):
number = int(input("Enter Number: "))
if(chkOdd(number)):
print("number is odd")
else:
print("number is even")
Output:
Enter Number: 21
number is odd
Enter Number: 10
number is even
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