Running on a particular treadmill you burn 3.9 calories per minute. Write a program that uses a for loop to display the number of calories burned after 10, 15, 20, 25, and 30 minutes.
I currently have this:
print("Minutes Calories")
print("--------------------------------------")
for i in range(10,30,5):
print(i)," ",print(i*3.9)
CodePudding user response:
You may use for i in range(10, 31, 5)
so that 30 minutes itself is included in the output as well.
CodePudding user response:
My solution:
print("Minutes\tCalories")
print("------------------")
for i in range(10,31,5):
print(i,"\t",i*3.9)
output:
Minutes Calories
------------------
10 39.0
15 58.5
20 78.0
25 97.5
30 117.0
CodePudding user response:
ratio = 3.9
times_to_calculate = [10, 15, 20, 25, 30]
print("Minutes\tCalories")
print("------------------")
for time in times_to_calculate:
print(time, "\t", ratio * time)
CodePudding user response:
You may want to use Python's f-strings to print your output.
print("Minutes Calories")
print("--------------------------------------")
for i in range(10,31,5):
print(f"{i: 2d} {i * 3.9: 3.1f}")
And the output is:
Minutes Calories
--------------------------------------
10 39.0
15 58.5
20 78.0
25 97.5
30 117.0