#------------------------------------------------- # Project: Take-Away Game # Standard: 91883 (AS1.7) v.1 # School: Tauranga Boys' College # Author: Alex Sanita # Date: # Python: 3.5 #------------------------------------------------- import random def main(): print("Welcome to the Guessing Game!") player_name = input("Please enter your name: ") player_score = 0 computer_score = 0 rounds_played = 0 while rounds_played < 3: print("Hello, it is now time to guess a number.") rounds_played += 1 round_winner = play_round(player_name) if round_winner == "player": player_score += 1 print("Congratulations! You won this round.") elif round_winner == "computer": computer_score += 1 print("Sorry, the computer won this round.") else: print("It's a tie for this round.") print("Round {rounds_played} complete.") print("Current score -> : {player_score}, Computer: {computer_score}") if player_score == 2: print("You has won the best of 3 rounds!") break elif computer_score == 2: print("\nThe computer has won the best of 3 rounds!") break print("\nGame Over!") if player_score > computer_score: print("You wins with a score of {player_score} to {computer_score}.") elif computer_score > player_score: print("The computer wins with a score of {computer_score} to {player_score}.") else: print("The game ended in a tie, with both scoring {player_score}.") def play_round(player_name): number_to_guess = random.randint(1, 1000) guesses_left = 10 print("\nA new number between 1 and 1000 has been chosen.") while guesses_left > 0: try: guess = int(input("You have {guesses_left} guesses left. Enter your guess: ")) except ValueError: print("Please enter a valid number.") continue guesses_left -= 1 if guess < number_to_guess: print("Your guess is too low! Try again.") elif guess > number_to_guess: print("Your guess is too high! Try again.") else: print("Congratulations You, you guessed the correct number!") return "player" print("Sorry, you've run out of guesses. The correct number was {number_to_guess}.") return "computer" if __name__ == "__main__": main()