Class 11 Computer Science Ch 7 Functions in Python NCERT Book Exercise Solution

Activity-based Questions

Note: Writing a program implies:
• Adding comments as part of documentation
• Writing function definition
• Executing the function through a function call

1. To secure your account, whether it be an email, online bank account or any other account, it is important that we use authentication. Use your programming expertise to create a program using user defined function named login that accepts userid and password as parameters (login(uid,pwd)) that displays a message “account blocked” in case of three wrong attempts. The login is successful if the user enters user ID as “ADMIN” and password as “St0rE@1”. On successful login, display a message “login successful”.

Answer: A

2. XYZ store plans to give festival discount to its customers. The store management has decided to give discount on the following criteria:

Shopping AmountDiscount Offered
=500 and <10005%
=1000 and <20008%
=200010%

An additional discount of 5% is given to customers who are the members of the store. Create a program using user defined function that accepts the shopping amount as a parameter and calculates discount and net amount payable on the basis of the following conditions:

Net Payable Amount = Total Shopping Amount – Discount.

Answer: A

3. ‘Play and learn’ strategy helps toddlers understand concepts in a fun way. Being a senior student you have taken responsibility to develop a program using user defined functions to help children master two and three-letter words using English alphabets and addition of single digit numbers. Make sure that you perform a careful analysis of the type of questions that can be included as per the age and curriculum.

Answer: A

4. Take a look at the series below:
1, 1, 2, 3, 5, 8, 13, 21, 34, 55…
To form the pattern, start by writing 1 and 1. Add them together to get 2. Add the last two numbers: 1+2 = 3.Continue adding the previous two numbers to find the next number in the series. These numbers make up the famed Fibonacci sequence: previous two numbers are added to get the immediate new number.

Answer: A

5. Create a menu driven program using user defined functions to implement a calculator that performs the following:
a) Basic arithmetic operations(+,-,*,/)
b) log10(x),sin(x),cos(x)

Answer: A

Suggested Lab. Exercises

1. Write a program to check the divisibility of a number by 7 that is passed as a parameter to the user defined function.

Answer: A

2. Write a program that uses a user defined function that accepts name and gender (as M for Male, F for Female) and prefixes Mr/Ms on the basis of the gender.

Answer: A

3. Write a program that has a user defined function to accept the coefficients of a quadratic equation in variables and calculates its determinant. For example : if the coefficients are stored in the variables a, b, c then calculate determinant as b2-4ac. Write the appropriate condition to check determinants on positive, zero and negative and output appropriate result.

Answer: A

3. ABC School has allotted unique token IDs from (1 to 600) to all the parents for facilitating a lucky draw
on the day of their Annual day function. The winner would receive a special prize. Write a program using
Python that helps to automate the task.(Hint: use random module)

Answer: A

4. Write a program that implements a user defined function that accepts Principal Amount, Rate, Time, Number of Times the interest is compounded to calculate and displays compound interest. (Hint: CI=P*(1+r/n)nt)

Answer: A

6. Write a program that has a user defined function to accept 2 numbers as parameters, if number 1 is less than number 2 then numbers are swapped and returned, i.e., number 2 is returned in place of number1 and number 1 is reformed in place of number 2, otherwise the same order is returned.

Answer: A

7. Write a program that contains user defined functions to calculate area, perimeter or surface area whichever is applicable for various shapes like square, rectangle, triangle, circle and cylinder. The user defined functions should accept the values for calculation as parameters and the calculated value should be returned. Import the module and use the appropriate functions.

Answer: A

8. Write a program that creates a GK quiz consisting of any five questions of your choice. The questions should be displayed randomly. Create a user defined function score() to calculate the score of the quiz and another user defined function remark (scorevalue) that accepts the final score to display remarks as follows:

MarksRemarks
5Outstanding
4Excellent
3Good
2Read more to score more
1Needs to take interest
0General knowledge will always help you. Take it seriously.

Answer: A

Case Study-based Question

For the SMIS system extended in Chapter 6 let us do the following:

1. 7.1 Convert all the functionality in Chapter 5 and 6 using user defined functions.

2. 7.2 Add another user defined function to the above menu to check if the student has short attendance or not. The function should accept total number of working days in a month and check if the student is a defaulter by calculating his or her attendance using the formula: Count of days the student was present or the total number of working days. In case the attendance calculated is less than 78%, the function should return 1 indicating short attendance otherwise the function should return 0 indicating attendance is not short.

Let’s peer review the case studies of others based on the parameters given under “DOCUMENTATION TIPS” at the end of Chapter 5 and provide a feedback to them.

Answer: A

Published on : February 3, 2022 | Last Updated on : March 6, 2022 | By Anjeev Kr Singh

You cannot copy content of this page

Scroll to Top