PRIP 3.2 Sumita Arora Solutions | Class 12 Computer Science

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)

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):
    s = n*1+n*2+n*3
    return s

N = 10
print(sumof3Multiples1(N))

(b)

def sumof3Multiples2(n):
    s = n*1+n*2+n*3
    print(s)

N = 10
sumof3Multiples1(N)

(c)

def areaOfSquare(a):
    return a*a

S = 10
Area = areaOfSquare(S)
Print(“Area of square: ”.format(Area))

(d)

def areaOfRectangle(a,b):
    return a*b

A = 10
B= 20
Area = areaOfRectangle(A, B)
Print(“Area of rectangle: ”.format(Area))

(e)

def perimeterCircle(r):
    return (2*3.1459*r )

R = 10
perimeter = perimeterCircle(R)
Print(“Perimeter of circle: ”.format(perimeter))

(f)

def perimeterRectangle( l, b):
    return 2*(l+b)

length= 20
breadth= 10
perimeter = perimeterRectangle(length, breadth)
Print(“Perimeter of rectangle: ”.format(perimeter))

(g)

def Quote():
    print(“\t Quote of the Day”)
    print(“Act Without Expectaton!”)
    print(“\t -Lao Tzu”)

Quotes()

(h)

def poly(x, y, z):
    s = x**3 + y**2 + z
    return s

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):
    s = n*1+n*2+n*3
    return s

if(__name__==”__main__”):
     N = input(“Enter number:”)
     print(sumof3Multiples1(N))

(b)

def sumof3Multiples2(n):
    s = n*1+n*2+n*3
    print(s)

If(__name__==”__main__”):
     N = input(“Enter number:”)
     sumof3Multiples1(N)

(c)

def Quote():
    print(“\t Quote of the Day”)
    print(“Act Without Expectation!”)
   print(“\t -Lao Tzu”)

If(__name__==”__main__”):
     print(Quotes())

(d)

def poly(x, y, z):
    s = x**3 + y**2 + z
    return s

if(__name__==”__main__”):
    X = input(“Enter x ”)
    Y = input(“Enter y ”)
    Z = input(“Enter z ”)
    S = poly(X, Y, Z)
    print(S)

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

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

You cannot copy content of this page