This is the code. Somebody please help. I'm confused. The guess
variable is the number of guesses that remain after each guess. I've tried global
and it still doesn't work. I'm lost at this point. Please help.
import random
# WELCOMING USER
print(" WELCOME TO THE NUMBER GUESSING GAME !! ")
print("The number you'll be guessing is between the range 1 - 100 ")
# SELECTING THE CORRECT GUESS RANDOMLY
correct_number = random.randint(1,100)
# ASKING THE USER FOR PREFERED DIFFICULTY AND SETTING NO OF GUESSES
difficulty_mode = input("Do you want the game to be easy or hard ? : ").lower()
guess = 0
#testing purposes
print(correct_number)
if difficulty_mode == "hard":
guess = 5
print("You have 5 guesses")
elif difficulty_mode == "easy" :
guess = 10
print(f"You have {guess} guesses")
else:
print("Wrong input")
# CREATING A FUNCTION TO REDUCE NO OF GUESSES
def reducing_guesses () :
global guess
guess -= 1
print(f"You have {guess} no. of guesses remaining ")
# CREATING A WHILE LOOP TO RUN GAME
isTrue = True
loop_rounds = 0
# ACTUAL WHILE LOOP
while isTrue == True :
if guess == 0:
isTrue = False
winning_or_loose = 0
if loop_rounds > 0 :
user_guess = int(input("Guess again : "))
if user_guess == correct_number :
isTrue == False
print(f"You win! You guessed:{user_guess} and it was correct ")
winning_or_loose = 1
else:
reducing_guesses()
if loop_rounds == 0 :
user_guess = int(input("Make a guess :"))
if user_guess == correct_number :
isTrue = False
print(f"You win! You guessed:{user_guess} and it was correct ")
winning_or_loose = 1
else:
reducing_guesses()