From 381b028c0e5dc6ed618771f29e8295d1e2e12441 Mon Sep 17 00:00:00 2001 From: Diana Alvarez <143985084+dianaalvarezz@users.noreply.github.com> Date: Tue, 20 Feb 2024 11:50:08 -0600 Subject: [PATCH] Update main.py finished documentation --- main.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main.py b/main.py index 17e25af..a92a844 100644 --- a/main.py +++ b/main.py @@ -12,28 +12,29 @@ lowernumber = int(input("Enter the lower bound number: ")) uppernumber = int(input("Enter the upper bound number ")) +# Generates the number that is to be guesssed within the specified range numtoguess = random.randint(lowernumber, uppernumber) -print("\n\tYou have only ", - round(math.log(uppernumber - lowernumber + 1, 2)), - " chances to guess the integer!\n") + +# Informs the player of the amount of chances they have +print("\n\tYou have only ", round(math.log(uppernumber - lowernumber + 1, 2)), " chances to guess the integer!\n") -guesses = 0 +guesses = 0 #Initialize the number of guesses that will be taken +# Loop that will continue until the user runs out of guesses while guesses < math.log(uppernumber - lowernumber + 1, 2): - guesses += 1 - - guess = int(input("Guess a number:- ")) + guesses += 1 # Increments the amount of guesses + guess = int(input("Guess a number:- ")) # Promts player the guess + # Checks to see if the guess was correct, too high, or too low if numtoguess == guess: - print("Congratulations you did it in ", - guesses, " tries") - + print("Congratulations you did it in ", guesses, " tries") break elif numtoguess > guess: print("The number you guesses is too small!") elif numtoguess < guess: print("The number you guesses is too large!") +# If player runs out of chances than allowed the game will give themm the correct answer if guesses > math.log(uppernumber - lowernumber + 1, 2): print("\nThe number was ", numtoguess, ". Nice try!")