import random # Check that the users entered a valid # option based on a list def string_checker(question, valid_ans=("yes", "no")): while True: user_response = input(question).lower() for item in valid_ans: if item == user_response: return item elif user_response == item[0]: return item def instructions(): """prints instructions""" print(""" *** Instructions *** To begin, choose the number of rounds (or infinite mode). Then play against the computer, with either R (rock), P (paper), or S (scissors). The rules are as follows: Paper beats rock Rock beats scissors Scissors beats paper Win the majority of rounds to win overall! """) def int_check(question): while True: error = "Please enter an integer that is 1 or more." to_check = input(question) if to_check == "": return "infinite" try: response = int(to_check) if response < 1: print(error) return "invalid" else: return response except ValueError: print(error) # Main Routine goes here # Initialise game variables mode = "regular" rounds_played = 0 rps_list = ["rock", "paper", "scissors", "xxx"] print(" Rock / Paper / Scissors Game") print() #ask the user if they want to see the instructions want_instructions = string_checker("Do you want to see the instructions? ") #Display the instructions if the user responded with yes if want_instructions == 'yes': instructions() # Ask user for number of rounds / infinite mode num_rounds = int_check("How many rounds would you like? press for infinite mode: ") if num_rounds == "infinite": mode = "infinite" num_rounds = 5 # game loop starts here while rounds_played < num_rounds: if mode == "infinite": rounds_heading = f"\n Round {rounds_played + 1} (Infinite) Mode" else: rounds_heading = f"\n Round {rounds_played + 1} of {num_rounds}" print(rounds_heading) print() user_choice = string_checker("Choose: ", rps_list) print("you chose", user_choice) if user_choice == "xxx": break comp_choice = random.choice(rps_list[:-1]) rounds_played += 1 if mode == "infinite": num_rounds += 1 # game loop ends here # game history / statistic area