Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I be able to input text instead of numbers (python)?

I’m making a simple program, but after inputting, there is always a ‘ValueError: invalid literal for int() with base 10’ after I try to put in a word. Basically, this program is supposed to make you type in a 3 letter word, but whenever I try and put in a word, there’s only an error message.

words = []
game = "play"
while game == "play":
    new = input("write something with 3 letters: ")
    if len(new) > 3 or len(new) < 3:
        print("That's not a 3 letter word.")
        
    else:
        if new in words:
            game = "over"
            print("you already said that word. Game over.")
            print("You know len(words), 3 letter words.")
else:
                print("u win")
                
                words.append(new)

did I do anything wrong? the problem seems to be in line 4???

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

I think I know whats going wrong 🙂

words = []
game = "play"
    while game == "play":
    new = input("write something with 3 letters: ")
    if len(new) > 3 or len(new) < 3:
        print("That's not a 3 letter word.")
    
    else:
        if new in words:
            game = "over"
            print("you already said that word. Game over.")
            print("You know len(words), 3 letter words.")
        else: # <---- you forgot a few tabs here ;)
            print("u win")
            words.append(new) # <---- this part is important

you never appended the new words to the list.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading