In: Computer Science
((PYTHON))
Finish the calories_burned_functions.py program that we started in class. Take the original calories_burned program and rework it so that it uses two functions/function calls.
Use the following file to get your program started:
"""
''' Women: Calories = ((Age x 0.074) - (Weight x 0.05741) +
(Heart Rate x 0.4472) - 20.4022) x Time / 4.184 '''
''' Men: Calories = ((Age x 0.2017) + (Weight x 0.09036) + (Heart
Rate x 0.6309) - 55.0969) x Time / 4.184 '''
"""
#Declare Variable names and types
age_years = int(input())
weight_pounds = int(input())
heart_bpm = int(input())
time_minutes = int(input())
#Performing Calculations
calories_woman = ( (age_years * 0.074) - (weight_pounds * 0.05741)
+ (heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184
calories_man = ( (age_years * 0.2017) + (weight_pounds * 0.09036) + (heart_bpm * 0.6309) - 55.0969 ) * time_minutes / 4.184
#Print and format results in detail
print('Women: {:.2f} calories'.format(calories_woman))
print('Men: {:.2f} calories'.format(calories_man))
"""
#Here are the functions to this program
def calc_calories_woman(years, pounds, heartrate,
minutes):
return ( (age_years * 0.074) - (weight_pounds * 0.05741) +
(heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184
#This is the main part of the program
#------------------------------------------------------------------------------
#Prompt the user at the keyboard for the necessary information
age_years = int(input("Please enter your age: "))
weight_pounds = int(input("Please enter your weight: "))
heart_bpm = int(input("Please enter your heart rate: "))
time_minutes = int(input("Please enter the time: "))
#Calculate the calories
calories_woman = ( (age_years * 0.074) - (weight_pounds * 0.05741) + (heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184
calories_man = ( (age_years * 0.2017) + (weight_pounds * 0.09036) + (heart_bpm * 0.6309) - 55.0969 ) * time_minutes / 4.184
#Print the results
print('Women: {:.2f} calories'.format(calories_woman))
print('Men: {:.2f} calories'.format(calories_man))
Python code pasted below.
#Function 1 for calculating the calories of women
def calc_calories_woman(years, pounds, heartrate, minutes):
return ( (age_years * 0.074) - (weight_pounds * 0.05741) +
(heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184
#Function 1 for calculating the calories of men
def calc_calories_man(years, pounds, heartrate, minutes):
return ( (age_years * 0.2017) - (weight_pounds * 0.057419036) +
(heart_bpm * 0.6309) - 55.0969) * time_minutes / 4.184
#main program
#Prompt the user at the keyboard for the necessary
information
age_years = int(input("Please enter your age: "))
weight_pounds = int(input("Please enter your weight: "))
heart_bpm = int(input("Please enter your heart rate: "))
time_minutes = int(input("Please enter the time: "))
#Function call 1 and print the results
print('Women: {:.2f}
calories'.format(calc_calories_woman(age_years,weight_pounds,heart_bpm,time_minutes)))
#Function call 2 and print the results
print('Men: {:.2f}
calories'.format(calc_calories_man(age_years,weight_pounds,heart_bpm,time_minutes)))
Python code in IDLE pasted for better understanding of the indent.
Output Screen