Running on a particular treadmill you bum a certain number of calories per minut
ID: 3673668 • Letter: R
Question
Running on a particular treadmill you bum a certain number of calories per minute (first user input). Write a program that uses a loop to display the number of calories burned after every 5 minute interval for a certain duration (second user input). The solution for this problem must be coded in a file named two.py The first input (a float number) must use the prompt "Enter calories burned per minute:" and the second input (an int number) must use the prompt "Enter duration of exercise in minutes: " The output should be present in a two-column format with a tab space between the two columns (see sample interaction below). The output should be done after all 5 minute intervals that lit within the exercise duration. E g. in the sample below, duration is 17 and the interval marked by 5. 10. 15 are shown, leaving out the remaining 2 minutes at the end of the duration Sample Interaction (output from program is shown in red and user input shown in blue):Explanation / Answer
two.py
print("Enter calories burned per minute")
cal=input()
#input taken is string by default,converting it to float for further calculations
calories_rate=float(cal)
print("Enter duration of exercise in minutes")
duration=input()
#input taken is string by default,converting it to int for further calculation
ex_duration=int(duration)
print("%s %s"%("Minutes","Calories Burned"))
print("------------------------------")
calories=0
for i in range(5,ex_duration,5):
calories=calories+calories_rate*5
#formatting the output in two columns with a tab space
print("{0:>5d} {1:>10f}".format(i,calories))
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.