Python Forum
Weight loss calculator loop error
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Weight loss calculator loop error
#1
Hello everyone,

This might be a fairly simple question but I am new to python and taking an online class pretty much instructing myself. Below is the problem with my current code.

# 11. Weight Loss
# If a moderately active person cuts their calories intake by 500 calories a day,
# they can typically lose about 4 pounds a month. Write a program that lets the
# user enter their starting weight, then creates and displays a table showing
# their expected weight will be at the end of each month for the next 6 months
# if they stay on this diet.

currentweight = int ( input ( "Enter your current weight: " ) )
monthlyloss = -4

for currentmonth in range ( 1, 7):
    weightlosspermonth = (currentweight + monthlyloss)

print ( currentmonth, "\t", weightlosspermonth )
The following is my output:

Output:
Enter your current weight: 200 1 196 2 196 3 196 4 196 5 196 6 196
Essentially, everytime the code loops, it should subtract 4 from the currentweight. At the end of the 6 months there should be 24 lbs lost. I can only get it to loop once subtracting the initial 4 pounds from the same weight everymonth. Can someone help me identify the issue?
Reply
#2
current_weight = int(input('enter your current weight:'))
monthlyloss = 4
for currentmonth in range(6):
    current_weight -= monthlyloss
    print('month: {}, weight: {}'.format(currentmonth + 1, current_weight)
Reply
#3
currentweight = 200
monthlyloss = -4
for currentmonth in range ( 1, 7):
	weightlosspermonth = (currentweight + monthlyloss)
	currentweight=weightlosspermonth
	print ( currentmonth, "\t", weightlosspermonth )
Thank you,
Learner
Reply
#4
Interesting..
How is your python program going on for healthcare field? Best wishes.
Reply
#5
(Oct-17-2017, 07:33 PM)drogers10940 Wrote: Hello everyone,

This might be a fairly simple question but I am new to python and taking an online class pretty much instructing myself. Below is the problem with my current code.

# 11. Weight Loss
# If a moderately active person cuts their calories intake by 500 calories a day,
# they can typically lose about 4 pounds a month. Write a program that lets the
# user enter their starting weight, then creates and displays a table showing
# their expected weight will be at the end of each month for the next 6 months
# if they stay on this diet.

currentweight = int ( input ( "Enter your current weight: " ) )
monthlyloss = -4

for currentmonth in range ( 1, 7):
    weightlosspermonth = (currentweight + monthlyloss)

print ( currentmonth, "\t", weightlosspermonth )
The following is my output:

Output:
Enter your current weight: 200 1 196 2 196 3 196 4 196 5 196 6 196
Essentially, everytime the code loops, it should subtract 4 from the currentweight. At the end of the 6 months there should be 24 lbs lost. I can only get it to loop once subtracting the initial 4 pounds from the same weight everymonth. Can someone help me identify the issue?
Reply
#6
Thank you very much All.
Reply
#7
Nikki - trying to get your post counts up? Not cool.

Zombie thread.
Reply
#8
hijacking someone else's thread can get you banned
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calculator Loop Help dock1926 3 3,861 Jun-23-2021, 10:05 PM
Last Post: HereweareSwole
  Python calculator help but not using while loop with true, any flags variable ,break kirt6405 13 5,731 Jun-08-2021, 06:39 AM
Last Post: Larz60+
  while loop on a calculator missus_brown 3 15,079 Feb-10-2019, 08:19 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020