""" ------------------------------------------------- Project: Take-Away Game Standard: 91883 (AS1.7) v.1 School: Tauranga Boys' College Author: Santosh Chitturi Date: THE DATE YOU COMPLETED THE CODE Python: 3.5 ------------------------------------------------- """ # Variables maxchips = 21 roundsPlayed = 0 player1_score = 0 player2_score = 0 # asking for the players' names def get_player_name(player_num): while True: name = input("What is your names, 2 completly random people I've never saw in my life " + str(player_num) + "? ").strip() if name.isalpha(): return name else: print("Please put a proper name in please!") name1 = get_player_name("who is going to be player 1") name2 = get_player_name("what is the second players name") # how many rounds are they while True: try: rounds = int(input("How many rounds do you guys want to play? (1-5): ")) if 1 <= rounds <= 5: break else: print("Please choose a number between 1 and 5.") except ValueError: print("Please choose a number between 1 and 5.") # Game loop for each round for round_num in range(1, rounds + 1): chipsleft = maxchips print("\nRound " + str(round_num) + ": " + str(chipsleft) + " chips remaining.") # Play each round until no chips are left while chipsleft > 0: # Alternate between players current_player = name1 if (round_num + chipsleft) % 2 == 1 else name2 print("\n" + current_player + "'s turn. " + str(chipsleft) + " chips left.") # Player takes chips while True: try: chips_taken = int(input(current_player + ": How many chips to take (1-3)? ")) if 1 <= chips_taken <= 3 and chips_taken <= chipsleft: chipsleft -= chips_taken break else: print("Please take between 1 and 3 chips, or less than remaining chips.") except ValueError: print("Please enter a valid number.") # Player who took the last chip wins the round if current_player == name1: player1_score += 1 else: player2_score += 1 print(current_player + " wins Round " + str(round_num) + "!\n") # Final score print("\nGame Over!") print(name1 + ": " + str(player1_score) + " points") print(name2 + ": " + str(player2_score) + " points") # Overall winner if player1_score > player2_score: print("\n" + name1 + " wins the game!") print(name2 + " is a loser!!") elif player2_score > player1_score: print("\n" + name2 + " wins the game!") print(name1 + " is a loser!!") else: print("\nIt's a tie! You both win!!")