I am new to Python and writing a program for a number guessing game. Here's the code:
import random
import math
def guessing_game_func():
name = input("Enter your name: ")
print("Welcome ", name)
lower_bound = 0
upper_bound = 50
#generating random number between 0 and 50
random_number = random.randint(lower_bound, upper_bound)
min_guessing_num = int(math.log(upper_bound - lower_bound + 1, 2))
print("INSTRUCTION: Guess a number between 0 and 50"
"\nHOT means you are close to the correct number and COLD means you are far from it")
print("You have only ", round(min_guessing_num), "tries")
#initializing number of guesses
count = 0
while count < min_guessing_num:
count += 1
guess = int(input("Guess a number: "))
if random_number == guess:
print("Congratulations. You guessed correctly after", count, "tries")
break
elif random_number > guess:
print("Hot")
elif random_number < guess:
print("Cold")
if count >= min_guessing_num:
print("Fail! The number is", random_number)
decision = input("Do you wish to play again? YES or NO").lower()
while decision == "yes":
guessing_game_func()
#if decision == "yes":
#guessing_game_func()
if decision == "no":
print("Close IDE")
guessing_game_func()
When I run this code, in the case where the user selects No, the game starts again but I do not want it to.
I just want it to print Close IDE
and that should be it. However, the game starts again and I know this is because I am calling the function after it, but if I do not do that, then nothing will happen. What I mean by this is that, the code will run and all I'll see is Process finished with exit code 0
How do I fix this please?