I’m supposed to find the weight of the dogs and while the loop did work, when I got an error and tried the variable, it just gave me 0.
I’m being asked to start a fixed loop 5 times and to enter the foodweight.
This is what i have right now
for loop in range(5):
foodweight=int(input("Please enter the weight of the food:"))
while foodweight<0 or foodweight>200:
print("Invalid, weight cant be less than 0 or more than 200")
foodweight=int(input("Please enter the actual weight of the food:'"))
totalweight+=foodweight
print(totalweight)
Instead of for example printing 400, it prints 0
>Solution :
If thats the correct indentation then you only ever add values that you enter after an invalid input first
unindent the line appending to total weight
while foodweight<0 or foodweight>200:
print("Invalid, weight cant be less than 0 or more than 200")
foodweight=int(input("Please enter the actual weight of the food:'"))
totalweight+=foodweight