why doesn\'t the else condition ever work when I enter this code. I purposefully
ID: 3889313 • Letter: W
Question
why doesn't the else condition ever work when I enter this code. I purposefully put in a actual current weight that is GREATER than the biweekly goal weight but it doesn't go to the else condition and print "I'm sorry but you did not reach your biweekly goal."
if eq(overallGoal.lower(), "lose weight") and (goalSetting.lower(),"biweekly"):
while True:
try:
actualWeight= int(input("Please enter your current weight in pounds after two weeks time. "))
break
except ValueError:
print("Invalid entry. Please enter numeric value only.")
break
if (actualWeight <= biweeklyWeight): #biweeklyWeight is the desired weight in two weeks time that was input by user in a portion above.
wghtlssbiwkPts=0
points= wghtlssbiwkPts + 250 #user is supposed to get points after obtaining this portion of the goal
else:
print("I'm sorry but you did not reach your biweekly goal.") #if they fail to meet the two week goal, they are supposed to be told that they did not reach it.
Explanation / Answer
You need to remove the break inside the try. I have assigned biweeklyWeight = 100 and actualWeight = 50 and 200. In both cases its working fine.
biweeklyWeight = 100
while True:
try:
actualWeight= int(input("Please enter your current weight in pounds after two weeks time. "))
#break
except ValueError:
print("Invalid entry. Please enter numeric value only.")
break
print(actualWeight)
print(biweeklyWeight)
if (actualWeight <= biweeklyWeight): #biweeklyWeight is the desired weight in two weeks time that was input by user in a portion above.
wghtlssbiwkPts=0
points= wghtlssbiwkPts + 250 #user is supposed to get points after obtaining this portion of the goal
else:
print("I'm sorry but you did not reach your biweekly goal.") #if they fail to meet the two week goal, they are supposed to
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.