Guessing Game does not work - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Guessing Game does not work (/thread-17678.html) |
Guessing Game does not work - the_entrepreneur - Apr-20-2019 i'm totally new to Python and I've been watching YouTube videos to get started with the language. In one of the videos, it showed us how to build a guessing game using while loops & if statements. I did the same, but it doesn't seem to work for me. secret_word = "harry" guess = "" guess_count = 0 guess_limit = 3 out_of_guesses = False while guess != secret_word and not(out_of_guesses): if guess_count < guess_limit: guess = input("Enter your guess: ") guess_count += 1 else: out_of_guesses = True if out_of_guesses: print("Out of guesses. Better luck next time!") else: print("Congrats! You win!")It gives me 3 tries, just like I specified. But when I type in the right word, it doesn't do anything. How do I fix this? RE: Guessing Game does not work - SheeppOSU - Apr-20-2019 I see the problem. the loop will keep going and won't go to the if statement because your not out of guesses secret_word = "harry" guess = "" guess_count = 0 guess_limit = 3 out_of_guesses = False while guess != secret_word: if guess_count < guess_limit: guess = input("Enter your guess: ") guess_count += 1 if guess != secret_word: print('try again') else: out_of_guesses = True if out_of_guesses == True: break if out_of_guesses: print("Out of guesses. Better luck next time!") else: print("Congrats! You win!") RE: Guessing Game does not work - the_entrepreneur - Apr-20-2019 I fixed the word guessing game. I dont know what the problem was, but I updated my 2018 PyCharm to 2019 PyCharm and it seemed to work. I have no idea why. Nevertheless, thanks for your help. But the calculator code still doesn't work. Help me with that, maybe? Thanks a lot man RE: Guessing Game does not work - SheeppOSU - Apr-20-2019 I posted problem to your calculator one here - https://python-forum.io/Thread-Python-Code-doesn-t-work |