Skip to content
Advertisement

I’m fairly new to python coding so I’m trying to challenge myself to do elif statements and I can’t find how to fix this problem [closed]

So here is my code and I can’t see what causes the error.

foods = int(input("What is your favorite food?: "))

if foods == apple:
    print("you like fruits!")
elif foods == pork:
    print("you like meat!")
elif foods == egg:
    print("you like poultry!")

The error is

line 3, in <module>
    foods = int(input("What is your favorite food?: "))
ValueError: invalid literal for int() with base 10: 'egg:'

Does anyone have any idea how to fix this?

Advertisement

Answer

The int part in the int(input(“What is your favorite food?: “)) line tries to convert the input string “egg” into an integer, which it canĀ“t. Remove it and the problem will go away.

Also, after the if == or elif ==, you need to write the food type as “egg”, “pork”, “apple”, otherwise python think you are referring to an variable and not a specific string.

Good luck!

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement