SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Tony Gaddis
Chapter:
Repetition Structures
Exercise:
Programming Exercises
Question:2 | ISBN:9780132576376 | Edition: 2

Question

Calories Burned
Running on a particular treadmill you burn 3.9 calories per minute. Write a program that uses a loop to display the number of calories burned after 10, 15, 20, 25, and 30 minutes.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

COMPLETE PYTHON CODE:

# Set starting time (in minutes)
time = 10

# Loop through time increments
while time <= 30:
  # Calculate the number of calories burned
  calories_burned = time * 3.9
  # Print results
  print(f"After {time} minutes, you have burned {calories_burned} calories.")
  # Increase time by 5 minutes
  time += 5

OUTPUT:

After 10 minutes, you have burned 39.0 calories.
After 15 minutes, you have burned 58.5 calories.
After 20 minutes, you have burned 78.0 calories.
After 25 minutes, you have burned 97.5 calories.
After 30 minutes, you have burned 117.0 calories.

 

0 0

Discussions

Post the discussion to improve the above solution.