Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Help - Guessing Game
#1
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;
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!! Big Grin
Reply


Messages In This Thread
Python Help - Guessing Game - by JamieT - Apr-15-2020, 07:25 PM
RE: Python Help - Guessing Game - by Larz60+ - Apr-15-2020, 07:54 PM
RE: Python Help - Guessing Game - by JamieT - Apr-15-2020, 09:14 PM
RE: Python Help - Guessing Game - by deanhystad - Apr-15-2020, 10:16 PM
RE: Python Help - Guessing Game - by JamieT - Apr-16-2020, 10:29 AM
RE: Python Help - Guessing Game - by deanhystad - Apr-16-2020, 01:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  word guessing game, hints STUdevil 1 1,758 Oct-12-2024, 01:53 AM
Last Post: menator01
Question Beginner Boolean question [Guessing game] TKB 4 4,450 Mar-22-2022, 05:34 PM
Last Post: deanhystad
  Unable to count the number of tries in guessing game. Frankduc 7 3,164 Mar-20-2022, 08:16 PM
Last Post: menator01
  Guessing game problem IcodeUser8 7 5,597 Jul-19-2020, 07:37 PM
Last Post: IcodeUser8
  Beginner Code, how to print something after a number of turns (guessing game) QTPi 4 3,881 Jun-18-2020, 04:59 PM
Last Post: QTPi
  Guessing game kramon19 1 2,721 Mar-25-2020, 04:17 AM
Last Post: deanhystad
  Help for guessing game code Kronos 5 4,506 Mar-09-2020, 04:53 PM
Last Post: snippsat
  guessing the number game go127a 6 6,395 Apr-27-2019, 01:23 PM
Last Post: go127a
  Guessing Game does not work the_entrepreneur 3 3,886 Apr-20-2019, 06:19 AM
Last Post: SheeppOSU
  Guessing Game with .WAV Files - Python Coding NonEntity 8 5,990 Nov-20-2018, 12:53 AM
Last Post: NonEntity

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020