#------------------------------------------------- # Project: Guessing game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Thomas Brighouse # Date: 15.03 # Python: 3.5 #------------------------------------------------- import random import time #Intro to the guessing game def play_game(): name = input("What is your name? ") print("Welcome to the Guessing game, {}!".format(name)) time.sleep(1.5) print("In this game, you will try to guess the number chosen by the computer.") time.sleep(1.5) print("You have 10 guesses per round. If you don't guess the number within 10 tries, you lose the round.") time.sleep(1.5) print("Your options are numbers between 1 to 1,000.") time.sleep(1.5) print("Good luck, {}!".format(name)) #Scoreboard scoreboard = {'player': 0, 'computer': 0} reset_guesses = 0 rounds = 3 user_score = 0 cpu_score = 0 round_won = True round_num = 1 #Loop for numbers while round_num <= rounds: print("\n--- Round {} ---".format(round_num)) cpu = random.randint(1, 1000) reset_guesses = 0 round_won = False while reset_guesses < 10: try: number = int(input("Guess the number: ")) reset_guesses += 1 #The player guesses right if number == cpu: print("Nice you got it right") user_score += 1 round_won = True break elif number < cpu: #If the player guesses too low print("That's too low. Try a bit higher.") #If the player guesses too high else: print("That's too high. Try a bit lower.") except ValueError: print("Please enter a valid number.") if round_won: print("You win this round! :D") else: print("You lose this round. The number was {}.".format(cpu)) cpu_score += 1 round_num += 1 print("\nGame Over!") print("Final Score:") print("Player Wins :D:", user_score) print("Computer Wins:", cpu_score) if __name__ == "__main__": play_game()