Hi all, you will have to excuse me, I am new to Python and have been learning over the past 2 days.
I have coded a basic guessing game and have a slight error.
First of all, I got the game to work perfectly as shown below;
I then tried to add in, "This is your last guess" which doesn't work in the correct way, it continues to offer me to answer, unless I guess correct then it will display "YOU WIN!"
Code shown below;
Cheers Guys!!
I have coded a basic guessing game and have a slight error.
First of all, I got the game to work perfectly as shown below;
secret_word = "spice"
guess = ""
guess_count = 0
guess_limit = 5
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, YOU LOSE!")
else:
print("YOU WIN!")I then wanted to advance and interact more by saying "this is your first guess" which works perfectly.I then tried to add in, "This is your last guess" which doesn't work in the correct way, it continues to offer me to answer, unless I guess correct then it will display "YOU WIN!"
Code shown below;
secret_word = "spice"
guess = ""
guess_count = 0
guess_limit = 5
out_of_guesses = False
guess = input("Enter your first guess: ")
while guess != secret_word and not (out_of_guesses):
if guess_count < guess_limit:
guess = input("Enter another guess: ")
guess_count += 1
elif guess != secret_word and not (out_of_guesses):
guess = input("Enter your last attempt: ")
else: out_of_guesses = True
if out_of_guesses:
print("Out of Guesses, YOU LOSE!")
else:
print("YOU WIN!")Can anybody advise, I will be very grateful.Cheers Guys!!
