Search code examples
if-statementinputpycharmintvalueerror

Can I use "if" in PyCharm for a word?


i'm pretty new in using Python and PyCharm so I'm looking for a little help here. Maybe this question can sound stupid for you, but trust me I'll be very happy for every answer I got here.

This is my code in PyCharm. I wanna make something like the Mad Libs program (is that really a name of it?) and I'm currently trying to find a way where program can figure out favourite color of User, haha. I copied the procedure which is working with numbers, but looks like words are very different.

error screenshot over here

Hopefully you can understand my weak english and my funny problem.

Thank you so much! - Alice <3


Solution

  • The problem in your code is on the following line:

    answer2 = int(input("My best color is "))
    

    You are trying to cast the user input to integer. This means that you are trying to 'convert' a string like purple in a number.
    This raised the error that you can see in the console.

    In order to fix it, you can use the following command instead:

    answer2 = input("My best color is ")