Reputation: 17
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
Reputation: 71
You were missing ()
for the .lower()
and I added this and guess != word
to 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
Reputation: 1106
lower()
is a function, not a property. Call the function to make it work.
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)
Guess the word: abets
abets
abets
Congrats!
1
<built-in method lower of str object at 0x000001EAEAF88CF0>
abets
Oops!
1
Upvotes: 1