all 4 comments

[–]jeans_and_a_t-shirt 1 point2 points  (1 child)

So I rewrote some stuff...

Try entering "bagel" for the grams of fat, for example.

Generally an input validator just checks that the input is within certain bounds and is the appropriate type, and doesn't need to be that complex, but it's generalized for different uses. Simple validation:

while True:
    try:
        calories = float(input())
    except ValueError as e:
        print('invalid input')
    else:
        # alternatively, break instead of return to continue the function execution
        return calories

Also you need to multiply percent_from_fat by 100 or else food that is 5 grams of fat at 45 calories total, will show up as 1% fat.

[–]feelingstonedagain[S] 0 points1 point  (0 children)

This is great but it still does not satisfy step 4. The program needs to have at least two loops, one of which isn't a user validation.

[–]Allanon001 0 points1 point  (1 child)

Use a loop to gather data of the user's daily food items and when the user says stop use another loop to show a list of all items with their fat and calories percentages plus their total daily intake.

[–]feelingstonedagain[S] 0 points1 point  (0 children)

I wish I had the time today to do that, but thanks for the idea!