Page 229 - Computer Science V2.0 Class 11
P. 229
8. Rewrite the following program after removing all the errors:
def compute(num1, num2):
result=0
result=num1 * num2
return result
compute()
print("The result is ", result)
9. Predict the output of the codes given below:
def compute(limit):
sum = 0
for p in range(1, limit+1):
sum += p
return sum
print(compute(5))
10. Write a function that takes a number as an argument and returns True if the number is odd, and False otherwise.
11. Write a function that takes radius as an input and computes the perimeter of circle.
12. Write a function that takes temperature in fahrenheit as an input and returns the equivalent temperature in celsius.
Assertion and Reasoning Based Questions
The following questions are assertion and reasoning-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): Organizing a program into smaller, independent sub-programs is called modular programming.
Reasoning(R): Each independent sub-program is called a module.
2. Assertion(A): Evaluating the following expression:
max('Anshul', 'Mridula', 'Shekhar', 'Ashish')
will yield 'Shekhar'.
Reasoning(R): max() takes only numeric values as arguments.
3. Assertion(A): Python allows the conversion of data from one data type to another.
Reasoning(R): int() is an example of a type conversion function.
Case-based Questions
1. Raman and Rishi are best friends. Raman is unable to understand the application of functions. He is of the opinion that
programs run successfully without functions, so why make the code complex? Rishi develops a function to test whether a
number is a prime and uses it in a program that accepts a number from a user and tests whether it is prime. He asks Raman
to create a similar program without functions. Keeping in mind the two programs, explain how Rishi's program has an edge
over Raman's program.
2. Noor is a retailer. She wants you to create a simple program for her that will accept an item name, price, and quantity and
calculate the amount. The program should have two user-defined functions as follows:
accept()–accepts name, price, and quantity
calculate()–takes price and quantity as arguments and returns the amount as price * quantity.
Introduction to Functions 215

