#------------------------------------------------- # Project: Take-Away Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Zack Norwood # Date: THE DATE YOU COMPLETED THE CODE # Python: 3.5 #------------------------------------------------- #imports the needed modules import random import time #Writes an introduction with instructions to the player name = input( "What is your name? " ) print( "Hello", name ) time.sleep(1) print( "In this game you will guess a number between 1 and 1000, and i will tell you higher or lower. " ) time.sleep(2) print( "If you do not guess my number with 10 chances, I win the round. " ) time.sleep(1.5) print( "If you guess my number before running out of guesses, you will win. " ) time.sleep(1.5) print( "Winner is best of 3 rounds. " ) time.sleep(1.5) tgames = 0 twins = 0 tloss = 0 #Sets the right values for each variable for the start of a new round def setup() : global guesses, round guesses = 10 round = round + 1 #Defines how the rounds will play out def round_() : global guesses, name, round, wins, loss #Sets the number that you need to guess between 1 and 1000 number = random.randint( 1, 1000 ) #Keeps the game playing until the player either runs out of guesses or guesses correctly while guesses > 0 : guess = int( input( "Take your guess, " ) ) if guess > number : print( "My number is lower than that" ) guesses = guesses - 1 elif guess < number : print( "My number is higher than that" ) guesses = guesses - 1 elif guess == number : print( "You got it" ) time.sleep(1) wins = wins + 1 break elif guess == number and wins == 2 : print( "You have bested me ") break #Once the loop has been broken, the game will finish the round adding to the loss or wins value where needed if guesses == 0 and round != 3 : print( "You lost this round." ) print( "Maybe you will be more fortunate in the next. " ) loss = loss + 1 if guesses == 0 and round == 3 : print( "You lost this round." ) loss = loss + 1 time.sleep(1) def play() : #Starts the code and sets the needed values for the beggining of the game global name, round, wins, loss, playagain, twins, tgames, tloss round = 0 wins = 0 loss = 0 tgames = 0 twins = 0 tloss = 0 #Sets the values back to how they need to be after a round is finished setup() round_() setup() print( "Welcome to round 2,", name ) round_() setup() #Determines whether a third round is needed if wins == 1 and loss == 1 : print( "Time for the next round. . . ") print( "Welcome to round 3,", name) round_() #Determines a winner if wins == 2 : print( "I have been defeated." ) time.sleep(1) playagain = input( "Go another game? (y/n)" ) twins = twins + 1 elif loss == 2 : print( "You've been beaten " ) time.sleep(1) playagain = input( "Maybe you'll be more fortunate in another game? (y/n) ") tloss = tloss + 1 #Runs the game until player chooses to stop playing play() while playagain == "y" : tgames = tgames + 1 print( "we have played", tgames, "games" ) print( "You've bested me", twins, "times, and lost", tloss, "times" ) play() #Writes a thank you for finishing the game print( "Thank you for playing!" )