In: Computer Science
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))
#include <stdio.h>
//function to calc calories of woman
double calc_calories_woman(int age_years,int weight_pounds,int heart_bpm,int time_minutes){
return ( (age_years * 0.074) - (weight_pounds * 0.05741) + (heart_bpm * 0.4472) - 20.4022 ) * time_minutes / 4.184;
}
//function to calc calories of man
double calc_calories_man(int age_years,int weight_pounds,int heart_bpm,int time_minutes){
return ( (age_years * 0.2017) + (weight_pounds * 0.09036) + (heart_bpm * 0.6309) - 55.0969 ) * time_minutes / 4.184;
}
int main()
{
//Getting The Inputs
int age_years = 0;
printf("Please enter your age: ");
scanf("%d",&age_years);
int weight_pounds = 0;
printf("Please enter your weight: ");
scanf("%d",&weight_pounds);
int heart_bpm = 0;
printf("Please enter your heart rate: ");
scanf("%d",&heart_bpm);
int time_minutes = 0;
printf("Please enter the time: ");
scanf("%d",&time_minutes);
//print the final result and calling the calc_calories function
printf("Women: %.2f calories\n",calc_calories_woman(age_years,weight_pounds,heart_bpm,time_minutes));
printf("Men: %.2f calories",calc_calories_man(age_years,weight_pounds,heart_bpm,time_minutes));
return 0;
}
Output: