Create a function called get_age() to input the user's age.  If the user enters    a value that is outside the specified range, throw a ValueError exception.   Create a function called fat_burning_heart_rate() to calculate and return the heart rate.    Try getting the user age input in main() along with the exception handling.    Prompt the user to continue the program with another age until the user indicates to quit.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

 Create a function called get_age() to input the user's age.  If the user enters
   a value that is outside the specified range, throw a ValueError exception.

  Create a function called fat_burning_heart_rate() to calculate and return the heart rate.

   Try getting the user age input in main() along with the exception handling.
   Prompt the user to continue the program with another age until the user indicates to quit.  

I have all of the main code written but I can't seem to figure out how to get it all within a main function that will restart when the user types yes and print bye bye for no. 

This is the kind of output I want:

This program calculates the fat-burning heart rate based on age.
Enter an age between 18-75: 35
Fat burning heart rate for a 35 year-old: 129.5 bpm
Would you like to try another age? (yes/no)yes
Enter an age between 18-75: 17
Invalid age.
Could not calculate heart rate info.
Would you like to try another age? (yes/no)yes
Enter an age between 18-75: 18
Fat burning heart rate for a 18 year-old: 141.39999999999998 bpm
Would you like to try another age? (yes/no)yes
Enter an age between 18-75: 75
Fat burning heart rate for a 75 year-old: 101.5 bpm
Would you like to try another age? (yes/no)no
bye-bye

This is the code I have so far:

def get_age():
    age = int(input("Enter an age between 18-75: "))
    if age < 18 or age > 75:
        raise ValueError('Invalid age.')
    return age

def fat_burning_heart_rate(age):
    heart_rate = (220 - age) * .7
    return heart_rate

if __name__ == "__main__":
    try:
        age = get_age()
        heart_rate = fat_burning_heart_rate(age)
        print("Fat burning heart rate for ", age, 'year-old: ',heart_rate, 'bpm')
    except ValueError as e:
        print(e)
        print("Could not calculate heart rate info.")

    user_input = input("Would you like to try another age? (yes/no): ")
    if user_input == 'no':
        print("bye-bye")
    if user_input == 'yes':
        get_age()

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Header Files
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education