0

The following equations estimate the calories burned when exercising (source):

Men: Calories = [(Age x 0.2017) — (Weight x 0.09036) + (Heart Rate x 0.6309) — 55.0969] x Time / 4.184

Women: Calories = [(Age x 0.074) — (Weight x 0.05741) + (Heart Rate x 0.4472) — 20.4022] x Time / 4.184

Write a program using inputs age (years), weight (pounds), heart rate (beats per minute), and time (minutes). Output calories burned for men and women.

Ex: If the input is:

49
155
148
60

Then the output is:

Men: 489.7772466539196 calories
Women: 580.939531548757 calories

My code -

age_years = float(input('Enter your age in years:\n'))
weight_lbs = float(input('Enter your weight in pounds:\n'))
heart_rate = float(input('Enter your heart rate in beats per minute:\n'))
time_min = float(input('Enter total time in minutes:\n'))
men_calories = [(age_years * 0.2017) - (weight_lbs * 0.09036) + (heart_rate * 0.6309) - 55.0969] * (time_min / 4.184)
women_calories = [(age_years * 0.074) - (weight_lbs * 0.05741) + (heart_rate * 0.4472) - 20.4022] * (time_min / 4.184)
print("Men:" , men_calories)
Error: Traceback (most recent call last):
  File "main.py", line 8, in <module>
    men_calories = [(age_years * 0.2017) - (weight_lbs * 0.09036) + (heart_rate * 0.6309) - 55.0969] * (time_min / 4.184)
TypeError: can't multiply sequence by non-int of type 'float'

What am I doing wrong here?

1
  • That's the keytel 2005 formula. It's supposed to be kilograms, not pounds. So your implementation o the math will give you roughly twice the actual calorie rate. Commented Jun 16, 2024 at 23:28

4 Answers 4

3

In Python, [] are used to define lists (sometimes called arrays in other languages), not as separators for expressions such as (), so, just use parentheses instead:

...
men_calories = ((age_years * 0.2017) - (weight_lbs * 0.09036) + (heart_rate * 0.6309) - 55.0969) * (time_min / 4.184)
women_calories = ((age_years * 0.074) - (weight_lbs * 0.05741) + (heart_rate * 0.4472) - 20.4022) * (time_min / 4.184)
...
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you it worked. But zybook is messing with me and saying its wrong :( Input 49 155 148 60 Your output Men: 489.77724665391963 calories Women: 580.939531548757 calories Expected output Men: 489.7772466539196 calories Women: 580.939531548757 calories
0

If you use the following expression it will round your answer up to the nearest ten thousandth. print('Women: {:.2f} calories_women') print('Men: {:.2f} calories_men') Hope that helps the next student out because the struggle is definitely REAL 🤔🤬😬😵😮🥱🤗

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
0
age_years = int(input())
weight_lbs = int(input())
heart_rate = int(input())
time_min = int(input())

men_calories = ((age_years * 0.2017) + (weight_lbs * 0.09036) + 
(heart_rate * 0.6309) - 55.0969) * time_min / 4.184
women_calories = ((age_years * 0.074) - (weight_lbs * 0.05741) + 
(heart_rate * 0.4472) - 20.4022) * time_min / 4.184
print('Women: {:.2f} calories'.format(women_calories))
print('Men: {:.2f} calories'.format(men_calories))

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
0

I actually made this lab harder that what it was. Here is what you need: Calories = ((Age x 0.2757) + (Weight x 0.03295) + (Heart Rate x 1.0781) — 75.4991) x Time / 8.368

Age=float(input())
Weight=float(input())
Heart_Rate=float(input())
Time=float(input())

Calories = float((Age * 0.2757) + (Weight * 0.03295) + (Heart_Rate * 1.0781) - 75.4991) * Time / 8.368

print('Calories: {:.2f} calories'.format(Calories))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.