0

I cannot seem to get the correct total from the 5 inputs. Anything I have tried so far has outputted seemingly random numbers. All I want to do is get the total number of grams entered. Any help would be appreciated.

totalWeight = 0
foodWeight = 0
allWeight = []

for counter in range (0, 4):
    print("Please enter the weight of the food in the containers")
    foodWeight = int(input("Please enter the weight of the food in the containers"))
    allWeight.append(foodWeight)
    totalWeight = sum(allWeight)

    while foodWeight < 0 or foodWeight >200:
        print("Invalid, a single container can only hold up to 200g")
    for counter in range (0, 4):
        foodWeight = int(input("Please enter the weight of the food in the containers"))
    break

totalWeight = totalWeight + foodWeight
print(totalWeight)
  • See [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) and slow down. Programming is not a game of "try a bunch of syntax until something works". You've got loops inside of loops doing random things. Take a moment to figure out what you want from your code and write down an algorithm on paper, as if you were writing a cooking recipe. Then start writing the code to do it. Randomly permuting lines of code is not going to get you the right answer. – Silvio Mayolo Feb 22 '22 at 17:19

0 Answers0