0% found this document useful (0 votes)
11 views2 pages

Functions Programming Exercises Guide

Uploaded by

Ajay D
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Functions Programming Exercises Guide

Uploaded by

Ajay D
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Adhiyaman Public Senior secondary School.

CHAPTER:3 Working with FUNCTIONS Programming Questions.


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”.

2. XYZ store plans to give festival discount to its customers. The store management has decided to
give discount on the following criteria:
Shopping Amount Discount Offered
>=500 and <1000 5%
>=1000 and <2000 8%
>=2000 10%
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.

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.

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 = [Link] 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 getthe immediate new number.

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)
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.

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.

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.

4. 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)

5. 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)

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.

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.

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:
Marks Remarks
5 Outstanding
4 Excellent
3 Good
2 Read more to score more
1 Needs to take interest
0 General knowledge will always help you. Take it seriously.

Common questions

Powered by AI

A function can determine and swap two numbers by accepting them as parameters and comparing their values. If the first number is less than the second, the function swaps their positions, returning the second number in place of the first and vice versa. Otherwise, the numbers are returned in their original order . This conditional logic highlights flexibility in numeric data manipulation when specific conditions are met.

A program can enhance security during the login process by using a user-defined function, such as 'login', which accepts user ID and password parameters. If the user fails to enter the correct user ID "ADMIN" and password "St0rE@1" within three attempts, the program displays a message “account blocked”. Upon successful login, the program outputs “login successful” . This method helps manage authentication attempts effectively and provides feedback on accessing restrictions.

A menu-driven calculator program should include both basic arithmetic operations, such as addition, subtraction, multiplication, and division, as well as scientific operations like log10(x), sin(x), and cos(x). This can be achieved through user-defined functions, where each function represents a specific operation. Users can select from a menu to execute their desired operation, enhancing functionality and user interaction . Such a program encapsulates a wide array of mathematical computations in an accessible user interface.

Programming can be used to create educational tools that help children learn through interactive activities, such as the 'Play and Learn' strategy. By developing programs with user-defined functions to teach two and three-letter words using English alphabets and basic arithmetic operations such as the addition of single-digit numbers, children can enjoyably learn foundational skills . These programs should align with children's age and educational curriculum, making learning engaging and effective.

The determinant of a quadratic equation, calculated as b²-4ac, offers critical insights into its roots. If the determinant is positive, the roots are real and distinct; if zero, the roots are real and equal; and if negative, the roots are complex conjugates . This evaluation enables predictions about root behavior without solving the equation explicitly, illustrating the theoretical properties of quadratic solutions.

To automate the process of selecting a winner using token IDs, a program can incorporate the use of the 'random' module in Python. This tool facilitates the random selection of token IDs from a predefined range, such as from 1 to 600, thus optimizing the fairness and time-efficiency of conducting a lucky draw during events like an Annual Day function . The use of automated random selection reduces bias and enhances the integrity of the draw process.

A general knowledge quiz program should include randomly displayed questions selected from a predefined set and functions to calculate scores and evaluate performance through remarks. After answering five questions, the score is calculated using a 'score' function, followed by a 'remark' function that provides feedback based on the score, ranging from 'Outstanding' to 'General knowledge will always help you' . This structure ensures a comprehensive assessment and tailored encouragement based on participant performance.

The Fibonacci sequence can be generated programmatically by starting with the numbers 1 and 1, and iteratively adding the last two numbers in the sequence to produce the next number. A user-defined function can be written to implement this pattern. The function takes two initial numbers and continues to add the last two numbers to generate subsequent numbers in the sequence . This approach efficiently demonstrates the property of using previous values to dictate future calculations.

To calculate discounts at a retail store, the program must apply different discount rates based on shopping amounts. If the shopping amount is between 500 and 1000, a 5% discount is applied; amounts between 1000 and 2000 get an 8% discount; and amounts over 2000 receive a 10% discount. Additionally, an extra 5% discount is offered to store members. The program calculates the net payable amount by subtracting the discount from the total shopping amount . This logic ensures an accurate and tiered discount application.

User-defined functions can effectively calculate the area and perimeter of geometric shapes by taking relevant dimensions as parameters, such as side length, radius, or base and height. Each function performs specific calculations depending on the shape, such as squares, rectangles, triangles, circles, and cylinders. These functions return the calculated values, providing a modular approach to geometric computations . This encapsulation facilitates reusable and organized code architecture for handling various geometric scenarios.

You might also like