Python Forum
Guessing Game "limit 4 attempts" help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Guessing Game "limit 4 attempts" help
#1
Hello, I am on the last problem in my intro to information systems course. This problem is extra credit and it would be nice to get that extra boost on my grade.
I have most of the guessing game complete, but upon guessing the incorrect number, the program continues to allow the user to guess. I have referred to a variety of sources in order to help me out. What am I doing wrong in my code?

Quote:import random

winning_number = random.randint (1, 10)

guesses_remaining = 4

print("You have four chances to guess the number!\n")

keep_playing = "true"
while keep_playing == "true":

guess = int(input("Guess a number between 1 and 10: "))

guesses_remaining = guesses_remaining - 1
if guess == winning_number:
print("Nice! You guessed the correct number.")
keep_playing= "false"
elif guess != winning_number:
print("\nIncorrect, please try again.\n")
else:
if guesses_remaining == 0:
print("You ran out of tries! Better luck next time.")
keep_playing = "false"
Reply


Messages In This Thread
Guessing Game "limit 4 attempts" help - by rprollin - Jun-22-2018, 06:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Play again, in a guessing game banidjamali 4 11,857 Jan-22-2021, 06:23 AM
Last Post: banidjamali
  Help - random number/letter guessing game juin22 1 3,237 Aug-16-2020, 06:36 AM
Last Post: DPaul
  making a guessing number game blacklight 1 2,222 Jul-02-2020, 12:21 AM
Last Post: GOTO10
  Guessing game with 4 different digits LinseyLogi 6 3,700 Mar-29-2020, 10:49 AM
Last Post: pyzyx3qwerty
  Guessing game with comparison operators Drone4four 9 13,863 Dec-02-2018, 06:12 PM
Last Post: ichabod801
  Looping over amount of attempts Beatenberg 4 6,320 Oct-17-2017, 07:47 AM
Last Post: Beatenberg
  Name guessing game in python Liquid_Ocelot 6 15,085 Apr-01-2017, 12:52 PM
Last Post: ichabod801
  guessing script simon 3 5,639 Oct-10-2016, 01:47 PM
Last Post: simon
  trying to get my random number guessing game to work! NEED HELP RaZrInSaNiTy 4 6,940 Oct-06-2016, 12:49 AM
Last Post: tinabina22

Forum Jump:

User Panel Messages

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