User238742837
User238742837

Reputation: 17

Track Number of Guesses for Word Guessing Game

I want to allow the users a maximum attempt of 6 to guess the correct word. Whenever I test run it and put in the correct word, it runs the else statement. I think I'm missing something simple but I can't figure it out.

ATTEMPTS = 6
count = 0
word = "abets"
guess = ""
while count < ATTEMPTS:
    guess = input("Guess the word: ").lower
    if guess == word:
        print("Congrats!")
        count += 1
    else:
        print("Oops!")
        count += 1
    print(count)

Upvotes: 0

Views: 228

Answers (2)

Prince
Prince

Reputation: 71

You were missing () for the .lower() and I added this and guess != wordto the while loop so that it stops after guessing the word.

ATTEMPTS = 6
count = 0
word = "abets"
guess = ""
while count < ATTEMPTS and guess != word:
    guess = input("Guess the word: ").lower()
    if guess == word:
        print("Congrats!")
        count += 1
    else:
        print("Oops!")
        count += 1
    print(count)

Upvotes: 2

Blue Robin
Blue Robin

Reputation: 1106

lower() is a function, not a property. Call the function to make it work.

Code:

ATTEMPTS = 6
count = 0
word = "abets"
while count < ATTEMPTS:
    guess = input("Guess the word: ").lower()
    print(guess)
    print(word)
    if guess == word:
        print("Congrats!")
        count += 1
    else:
        print("Oops!")
        count += 1
    print(count)

Output:

Guess the word: abets
abets
abets
Congrats!
1

Output without lower as a function:

<built-in method lower of str object at 0x000001EAEAF88CF0>
abets
Oops!
1

Upvotes: 1

Related Questions