So here is my code and I can’t see what causes the error.
JavaScript
x
9
1
foods = int(input("What is your favorite food?: "))
2
3
if foods == apple:
4
print("you like fruits!")
5
elif foods == pork:
6
print("you like meat!")
7
elif foods == egg:
8
print("you like poultry!")
9
The error is
JavaScript
1
4
1
line 3, in <module>
2
foods = int(input("What is your favorite food?: "))
3
ValueError: invalid literal for int() with base 10: 'egg:'
4
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!