#-------------------------------------------------------------------------- # Project: Guess the Number Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Seb Drew # Date: THE DATE YOU COMPLETED THE CODE # Python: 3.5 # #-------------------------------------------------------------------------- # Import Random import random # Setting Functions reset_guesses = 1 rounds = 3 user_score = 0 AI_score = 0 round_won = True round = 1 # Game Title print("╔═════════════════════════════════════╗") print("║ ║") print("║ GUESS THE NUMBER ║") print("║ ║") print("╚═════════════════════════════════════╝") # Ask for user name while True: name = input("What is your name? ") if name.isalpha() == True: break else: print("Please enter a string input") #Welcome User and explain game print("Hello {}, welcome to the GUESS THE NUMBER GAME!!!!".format(name)) print("The aim of this game is to guess the number, a computer randomly generated form 1 to 1000.") print("You have 10 guess, each guess, the computer will stat that wether you will need to go higher of lower based on your last guess.") print("It is game of best of 3.") # Start of rounds loop while round < 4 and user_score or AI_score < 2: number = random.randint(1, 1000) guesses = reset_guesses #Outputing the round and score print("") print("Round {}".format(round)) print("User score {}".format(user_score)) print("AI score {}".format(AI_score)) #start of guess loop while guesses < 11: print("") print("Guess {}".format(guesses)) user_guess = int(input("Guess the number ")) guesses = guesses + 1 if user_guess == number : print("Congrats, you guessed the number. You have won a round.") round_won = True break #saying if you need to go higher elif user_guess < number: print("Higher") #saying if you need to go lower elif user_guess > number: print("Lower") print("GUESS {}".format(guesses)) #saying out of guess else: print("") print("You have ran out of guesses") print("The number was", number) round_won = False #givine player 1 point if round_won == True: user_score = user_score + 1 round = round + 1 #givine AI 1 point elif round_won == False: AI_score = AI_score + 1 round = round + 1 #Output Text if user_score == 2: print("") print("User score {}".format(user_score)) print("AI score {}".format(AI_score)) print("") print("Congradulations ", name, " you have won 2 rounds and beaten the AI. You are the Overall winner.") print("╔═══════════════════════════════════╗") print("║ ║") print("║ TO COOL FOR YOU ║") print("║ ║") print("╚═══════════════════════════════════╝") elif AI_score == 2: print("") print("User score {}".format(user_score)) print("AI score {}".format(AI_score)) print("") print("Nice try ", name, ", but the AI has won 2 rounds before you and has beaten you. You are a loser.") print("╔═══════════════════════════════════╗") print("║ ║") print("║ YOU ARE A LOSER ║") print("║ ║") print("╚═══════════════════════════════════╝")