Lab 6: Functions
Points Possible: 100
Due: Thursday, October 10th
In this lab, we will write programs using functions.
Submission:
- Submit a Python file for each of the programs.
Program 1: Calculate Discount
Write a function calculate_discount
that takes as input 2 parameters: price, discount rate (in %), and return the discount.
Write a test program to read the price and discount rate values (using input statements outside the function) and display the discount by calling the calculate_discount
function (invoke function) and printing the return value of the discount.
Save the program is discount.py
and attach it to the Blackboard lab assignment.
Program 2: Divide By
Write 3 functions with the requirement as mentioned below:
- Write a function
divBy5(num)
that takes as input a number and returnsTrue
if the number is divisible by 5. It returnsFalse
otherwise. - Write a function
divBy6(num)
that takes as input a number and returnsTrue
if the number is divisible by 6. It returnsFalse
otherwise. - Write another function
divBy5and6(num)
that takes as input a number num and callsdivBy5(num)
anddivBy6(num)
. The function returnsTrue
if the output/returned values from bothdivBy5(num)
anddivBy6(num)
areTrue
. It returnsFalse
otherwise.
Write a test program to read a number from the user (using an input statement outside the functions) and call the divBy5and6(num)
function (invoke function) and printing the return value from the function.
Save the program is divideby.py
and attach it to the Blackboard lab assignment.
Grading Rubric for each of the functions:
Grading | Points Possible |
Appropriate docstring and comments | 5 |
Input and output | 5 |
Computation | 10 |
Function invocation | 5 |
TOTAL 25 points for each function