CpE201 – Object Oriented Programming (Advanced Prog.
) Spring 2021
Assignment 2: Functions
Due: Thursday May 6, 2021 @ 12:00 pm soft copy in Moodle.
Maximum: 100 points
Q1) Write a health record program. Your program should read the following values from the
user:
• Name
• Date of birth in dd/mm/yyyy format
• Height (in meter)
• Weight (in Kg)
Your code should have the following functions:
• computeAge : calculate and return the user’s age in years. To compute the age, use the
date python module to find the current year (date.year from the datetime python
module)
• computeMHR: calculate and return the maximum heart rate. According to the American
Heart Association (AHA) (www.americanheart.org/presenter.jhtml?identifier=4736), the
formula for calculating your maximum heart rate in beats per minute is 220 minus your
age in years
• computeBMI: calculate and return the user’s body mass index (BMI). The formula for
calculating BMI is
𝑤𝑒𝑖𝑔ℎ𝑡𝐼𝑛𝐾𝑖𝑙𝑜𝑔𝑟𝑎𝑚𝑠
𝐵𝑀𝐼 =
ℎ𝑒𝑖𝑔ℎ𝑡𝐼𝑛𝑀𝑒𝑡𝑒𝑟𝑠 2
After reading the values from the users,
• Calculate and print the user’s age.
• Calculate and print the user’s maximum heart rate
• Calculate and print the user’s BMI
• Print the BMI category according to the following rule:
BMI VALUES
Underweight: less than 18.5
Normal: between 18.5 and 24.9
Overweight: between 25 and 29.9
Obese: 30 or greater
The program can read as many inputs as the user wishes. Your program should terminate if the
user entered “.” for any of the inputs.
Example Execution (user input in green)
Enter your name: Manar
Enter your date of birth: 1/1/2002
Enter your height in meter: 1.46
Enter your weight in kg: 56
Manar's age is 19
Your maximum heart rate is 201
Your BMI is 26.27 --> Overweight
Enter your first name: Manar
Enter your date of birth: .
Thank you! Bye
Q2) Rock, Paper, Scissors Game
Write a program that lets the user play the game of Rock, Paper, Scissors against the computer.
The program should work as follows:
• When the program begins, a random number in the range of 1 through 3 is generated.
If the number is 1, then the computer has chosen rock. If the number is 2, then the
computer has chosen paper. If the number is 3, then the computer has chosen scissors.
(Don’t display the computer’s choice yet.)
• The user enters his or her choice of “rock,” “paper,” or “scissors” at the keyboard.
• The computer’s choice is displayed.
• A winner is selected according to the following rules:
• If one player chooses rock and the other player chooses scissors, then rock wins.
(Rock smashes scissors.)
• If one player chooses scissors and the other player chooses paper, then scissors wins.
(Scissors cuts paper.)
• If one player chooses paper and the other player chooses rock, then paper wins.
(Paper wraps rock.)
• If both players make the same choice, the game must be played again to determine the
winner.
Use modularization to enhance your code readability and reuse. You must use one or more
functions in your program.
Example Execution (user input in green)
Enter 1 for rock, 2 for paper, 3 for scissors: 1
Computer chose rock
You chose rock
You made the same choice as the computer. Starting over
Enter 1 for rock, 2 for paper, 3 for scissors: 2
Computer chose scissors
You chose paper
The computer wins the game
Submission instructions:
• You are required to submit your source code (.py) for each question unless specified otherwise.
• At the beginning of each code add a comment specifying your name, assignment #, and question
# following the below format:
‘’’
Your name [First last]
ID
Homework x
Question x
Collaborators xx
‘’’
• At the end of your code add as a comment your answer for each question (if any) along with
your code sample output.
• Compress the source code file(s) (using zip or tar) and submit the compressed file through
Moodle. The compressed file naming should be like the following:
[studentID]_[studentName]_[HW#].zip