Page 296 - Computer Science Class 11 With Functions
P. 296
Objective: To accept data from the user
Inputs: NIL
Return value:
ans : menu option to be accepted by the user
'''
print("Enter two numbers ")
number1 = int(input("Number 1 : "))
number2 = int(input("Number 2 : "))
ans = menu() # Nested function
if ans == 1:
addition(number1,number2) # Nested function
elif ans == 2:
product(number1,number2) # Nested function
elif ans == 3:
difference(number1,number2) # Nested function
elif ans == 4:
divide(number1,number2) # Nested function
else:
print("Wrong Choice ")
userInputs()
Output:
Enter two numbers
Number 1 : 90
Number 2 : 6
Addition Operation
The sum is 96
Multiplication Operation
The product is 540
Subtraction Operation
The difference is 84
Division Operation
The quotient is 15 and the remainder is 0
Note that the user-defined functions are executed in the order of their respective function call statements and not in order of
their sequence of definition (difference(), product(), addition(), divide()). Also, note that each function contains the docstring that
describes its objectives, data to be accepted and return values.
Assertion and Reasoning Based Questions
The following questions are assertion(A) and reasoning(R) based. Mark the correct choice as
a. Both A and R are true and R is the correct explanation of A
b. Both A and R are true and R is not the correct explanation of A
c. A is true but R is false
d. A is false but R is true
1. Assertion(A): Modules make the code reusable.
Reasoning(R): In a Python program, the functions of a module may be called even before the module is imported.
294 Touchpad Computer Science-XI

