#------------------------------------------------- # Project: Take-Away Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Travis Enright # Date: THE DATE YOU COMPLETED THE CODE # Python: 3.5 #------------------------------------------------- #Imports #------------------------------------------------- import random import time #Variables #------------------------------------------------- current_round = 0 chips_remaining = 0 player1_chips_taken = 0 player2_chips_taken = 0 rounds = 0 player1_score = 0 player2_score = 0 #Constants #------------------------------------------------- START_CHIPS = 21 #Functions #------------------------------------------------- def display_round(): print( "round {} ---------------------------".format(current_round)) print("The score is {} - {}".format(player1_score,player2_score)) #intro print( "Welcome to the Take-Away Game!") print(" ") print( "What Are your names?" ) #asks for player_1 and player_2's name #if the input is not a string it will ask the used to try again while True: print(" ") player_1 = str(input( "What is player 1's name? " )) if player_1.isalpha() == True: break else: print( "That is not an acceptable name please try again" ) while True: print(" ") player_2 = str(input( "What is player 2's name? " )) if player_2.isalpha() == True: break else: print( "That is not an acceptable name please try again" ) #asks how many rounds the user would like to play #if the input is too high or low it will asked for the user try again #if it is not a integer it will ask the user to try again while True: try: rounds = int(input( "How many rounds would you like to play? " )) if rounds < 1 or rounds > 100: print( "That is not a number between 1-100 please try again" ) else: break except: print( "That is not a number please try again") print( "Welcome {} and {}".format(player_1,player_2)) print( "{} will start".format(player_1)) while rounds > 0: chips_remaining = START_CHIPS display_round() while chips_remaining > 0: player1_chips_taken = 0 player2_chips_taken = 0 print( "{} chips left".format(chips_remaining)) while True: try: player1_chips_taken = int(input("How many chips would {} like to take? (1-3) ".format(player_1))) if player1_chips_taken < 1 or player1_chips_taken > 3 or player1_chips_taken > chips_remaining: print("That is not a number between 1-3 please try again") else: break except: print( "That is not a number please try again") chips_remaining = chips_remaining - player1_chips_taken if chips_remaining == 0: player1_score = player1_score + 1 current_round = current_round + 1 rounds = rounds - 1 else: print( "{} chips left".format(chips_remaining)) while True: try: player2_chips_taken = int(input("How many chips would {} like to take? (1-3) ".format(player_2))) if player2_chips_taken < 1 or player2_chips_taken > 3 or player2_chips_taken > chips_remaining: print("That is not a number between 1-3 please try again") else: break except: print( "That is not a number please try again") chips_remaining = chips_remaining - player2_chips_taken if chips_remaining == 0: player2_score = player2_score + 1 current_round = current_round + 1 rounds = rounds - 1 #displays who the winner is if player1_score > player2_score: print("{} wins!!!".format(player_1)) elif player1_score == player2_score: print("Tie!!!") else: print("{} wins!!!".format(player_2))