Jun-22-2018, 06:18 PM
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?
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"