""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: YOUR FULL NAME Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ import time #functions def determine_winner(name1, name2, name1_score, name2_score): #this is defining a fuction with four parameters if name1_score > name2_score: #this part are the condtional statments that occor based on the differnt scores of the players print("Congratulations", name1, "you win. Better luck next time", name2) elif name2_score > name1_score: print("Congratulations", name2, "you win. Better luck next time", name1) else: print("It's a tie!") def name_checker(name): #this defines the name checker function and is ready for it to be called upon to check a name if name.isalpha(): #if the name has alphabeical letter it returns valid or true return True else: #if it doesnt it returns false and asks for a name with letters in the alphabet print("please write a name with letters in the alphabet") return False #End of functions MAX_CHIPS = 21 name1_score = 0 name2_score = 0 chips_left = 0 chips_taken = 0 print("hello, weclome to the chips game, whoever picks the last chip wins.") name1 = input("What is player ones name? ") while not name_checker(name1): #calls upon the name checker function to check if name1 is valid, if it is valid it keeps going normally name1 = input("What is player ones name? ") #if its not valid it asks again name2 = input("What is player twos name? ") while not name_checker(name2): #calls upon the name checker function to check if name2 is valid name2 = input("What is player twos name? ") #if its not valid it asks again while True: try: rounds = int(input("how many rounds would you like to play (1-5)? ")) if rounds < 1 or rounds > 5: #if the user inputs a number above 5 or below 1, it asks again# print("please choose a number between 1 and 5 ") else: break except ValueError: print("please input a number between 1 and 5") #if they dont input anything, ask them again# current_player = name1 #set current player to 1 for player one to start off the game while rounds > 0: print("rounds left:", rounds) time.sleep(1) print("start of round") time.sleep(1) chips_left = MAX_CHIPS while chips_left > 0: #while there are more than 0 chips left run this code# print("chips left:", chips_left) time.sleep(1) while True: try: max_chips_to_take = min(3, chips_left) # max chips a player can take is 3 or how many chips are remaining chips_taken = int(input(f"how many chips would {current_player} like to take from the pile (1-{max_chips_to_take})? ")) #current player is used as a function which means it can be switched out between player1 and player2 depending on whose trun it is if 1 <= chips_taken <= max_chips_to_take: # this checks if the chips taken is a valid number not below 1 or above the max_chips_to_take chips_left -= chips_taken break else: print(f"Please choose a number between 1 and {max_chips_to_take}") #if its not valid ask for a valid number except ValueError: print("please valid number, not below 1 and maximum is", max_chips_to_take) #if they dont input anything, ask them again# if chips_left < 1: if current_player == name1: # if there are no chips left and current player is player1 increase player1 score by 1 name1_score += 1 else: # if there are no chips left and current player isnt player1 (so it has to be player2) increase player2 score by 1 name2_score += 1 print(f"{current_player} has won the round! ") print(f"{name1} score:", name1_score, f"{name2} score:", name2_score) #at the end output the total scores of both players break if current_player == name1: #at the end, set up for the next players turn current_player = name2 # if the current player is name1 change current player to player2 so its now his turn else: # and if current player isnt player1 change is to player 1 (basicly if its player 2 change to player 1 for same reason as prevous comment) current_player = name1 rounds -= 1 determine_winner(name1, name2, name1_score, name2_score) #this calls upon the function and gives it the values of the four parameters for it to then use to detemine what condtional statement to print