import random import time # Asking for the player's name and explaining the game player_name = input("What is your name, player? ") print(f"Hello {player_name}! Welcome to the one and only guess the number game. The computer will choose a number between 1 - 1000 and you will have 10 guesses to get the right number. The game will be a best of 3, so winning 2 rounds means you win. Good luck!") # Setting up the variables and having the computer generate a number between 1 - 1000 random_number = random.randint(1, 1000) rounds_won = 0 rounds_lost = 0 current_round = 1 retry_round = 0 guesses_left = 10 # Provide a hint based on the generated random number # Provide a hint if it's the first guess if guesses_left == 10: if random_number < 100: print("Here's a hint: It's a two digit number.") elif random_number > 100 and random_number <= 200: print("Here's a hint: The number is above a century") elif random_number > 200 and random_number <= 300: print("Here's a hint: The number is more than double a century") elif random_number > 300 and random_number <= 400: print("Here's a hint: The number is bigger than 300 the comic book") elif random_number > 400 and random_number <= 500: print("Here's a hint: The number is bigger than the longest living vertebrate's age") elif random_number > 500 and random_number <= 600: print("Here's a hint: The number is bigger half a mellinnium") elif random_number > 600 and random_number <= 700: print("Here's a hint: The number is bigger than Khalid bin Mohsen Shaari's weight") elif random_number > 700 and random_number <= 800: print("Here's a hint: The number is bigger than the XUV700's number") elif random_number > 800 and random_number <= 900: print("Here's a hint: The number is bigger than 800 the film") elif random_number > 900 and random_number <= 1000: print("Here's a hint: The number is bigger than Microsoft Wireless Desktop 900's number") # You can change the number variables and hint amounts to make it harder or easier # Making sure the game will only continue if no one loses 2 rounds while rounds_won < 2 and rounds_lost < 2: guesses_left = 10 random_number = random.randint(1, 1000) # Game logic for each round while True: time.sleep(0.5) player_guess = int(input(f"Hello {player_name}, guess a number and I will tell you if it's higher, lower, or somehow the right number: ")) guesses_left -= 1 # Asking the user for their number choice and setting it so the round can end and so can the game if player_guess == random_number: time.sleep(2) # Giving the game a feeling of the computer actually checking the number print("Congratulations! You guessed the number correctly. You win this round!") rounds_lost += 1 current_round += 1 break elif player_guess > random_number and guesses_left >= 1: time.sleep(2) print("Your guess was too high. The number is lower.") elif player_guess < random_number and guesses_left >= 1: time.sleep(2) print("Your guess was too low. The number is higher.") elif guesses_left <= 0: time.sleep(2) print("Oh no! You ran out of guesses. Better luck next time.") rounds_won += 1 current_round += 1 break # Ending the round and moving onto the next round of the game if the player chooses if rounds_won < 2 and rounds_lost < 2: print(f"Current score: Computer won {rounds_won} rounds, Player won {rounds_lost} rounds") time.sleep(0.5) retry_round = int(input(f"Hello {player_name}, enter 1 to start the next round or 2 to end the game: ")) guesses_left = 10 if retry_round == 2: break # Check if the computer or player has won the game if rounds_won >= 2: print("HAHA! You lost to a computer program. Better luck next time.") elif rounds_lost >= 2: print("WHAT! Go on, start another game and see how badly you lose. I don't care if you win anyway. *pfft*")