#------------------------------------------------- # Project: Guessing Game # School: Tauranga Boys' College # Author: Mr Ronowicz # Date: THE DATE YOU COMPLETED THE CODE # Python: 3.8 #------------------------------------------------- # Imort Libraries import random ################### Set starting variable values ################# RESET_GUESSES = 0 # Reset guesses at the beginning of a round rounds = 3 # Set game rounds to 3 user_score = 0 # Set players starting score to zero computer_score = 0 # Set computers starting score to zero round_win = True #Initiate round_win bool variable round = 1 # Used to inform user of each round. Increases by 1 ###################### GAME INTRODUCTION ########################## print("Welcome to the Number Wizard Game") # Welcome Message # Store players name in a variable name = input("What is your name? ") # Greet player by name and give an overview of how the game is played print("Hello {}. \nIn this game you need to guess the random number between 1 and 1000 in as little guesses as posssible...".format(name)) print() print("If you can pick the number in less than 10 guesses you win! we will play a best of 3 games") print() ####################### START OF ROUNDS LOOP ####################### for i in range(1, rounds + 1): # For in range loop used to track the 3 rounds correct_number = random.randint(1, 100) # Setting the random number to guess round_win = False # round_win variable set to false so that we can identify a correctly guessed number and increase player score guesses = RESET_GUESSES # Starting guesses set to zero using constant print() print("Welcome to round {}".format(round)) # Output current round print("{} score is: {}".format(name, user_score)) # Output players score print("Computerscore is: {}".format(computer_score))# Output computers score #################### START OF GUESSES LOOP ####################### while guesses < 10: # Wjile loop used to count to 10 guesses print() pick = int(input("Please guess a number: ")) # Asks user for guess #### Condidtions used to decide action on users choice ##### # If user picks the correct number if pick == correct_number: print("You picked the right number!:", correct_number) # Let user know pick is correct round_win = True # round_win set to True to increase player score guesses = 10 # gesses set to 10 to exit guesses loop # If user has picked an inccorect number elif guesses < 9: # Conditional stament to inform user to guess higher or lower if pick < correct_number: print("You need to pick higher") else: print("You need to pick lower") # If guesses are 9 or greater, user will not be instructed to pick higher or lower, only that they are out of guesses else: print("Out of guesses") guesses += 1 # Add one to guesses # Condition using round_win Bool to calculate score if round_win == True: user_score += 1 else: computer_score += 1 # Add 1 to round round += 1 # As game is best of 3, check game is not won before 3rd round if user_score == 2 or computer_score == 2: break # used to break out of the rounds loop if either condition is met ################### END OF GAME OUTPUT PLAYER SCORES############## if computer_score > user_score: print("\nComputer Score:", computer_score) print("Your score:", user_score) print("You loose") else: print("\nYour score:", user_score) print("Computer Score:", computer_score) print("You win")