# V1 get the program to run using 5 questions with basic functionality # Check that users have entered a valid # option based on a list def string_checker(question, valid_ans): while True: error = f"Enter a valid option from {valid_ans}" user_response = input(question).upper() for item in valid_ans: # check if the user response is a valid answer if item == user_response: return item elif user_response == item[0]: return item print(error) print() def instructions(): print(''' **** Instructions **** To begin, choose the number of rounds (or press for infinite mode). Press xxx to end the game at any time ''' ) # compare the comp selection v the user input # result - win, lose or tie def rps_compare(user, comp): if user == comp: round_result = "correct" else: round_result = "incorrect" return round_result # checks the input is an integer def int_check(question): while True: error = "Enter an integer more than 1" to_check = input(question) try: response = int(to_check) # check the number is more than 1 if response >= 1: return response else: print(error) except ValueError: print(error) # Main routine # quiz variables rounds_played = 0 rounds_lost = 0 rounds_won = 0 yes_no = ["YES", "NO"] patai_list = ["What is the indigenous language of New Zealand?", "What is the traditional Māori name for New Zealand?", "What is a traditional Māori meeting house called?", "What is the traditional Māori weapon used for close combat?"] answer_list = ['A', 'B', 'C', 'D'] options_list = ["A. Te Reo Māori\nB. Sign Language\nC. English\nD. Cook Island Māori\n", "A. Wharekauri\nB. Aotearoa\nC. Te Waipounamu\nD. Te ika a Māui\n", "A. Whareiti\nB. Wharekai\nC. Wharenui\nD. Wharepaku\n", "A. Taiaha\nB. Rakau\nC. Tewhatewha\nD. Mere\n"] game_history = [] print() print(" ⛰️ 🧻 ✂️ Māori General Knowledge Quiz ⛰️ 📰 ✂️ ") print() print("** Welcome to the Māori General Knowledge Quiz **") print() # instructions want_instructions = string_checker("Do you want to see the instructions? ", yes_no) if want_instructions == "yes": instructions() num_rounds = int_check("Enter the number of rounds ") # game loop starts here while rounds_played < num_rounds: # Heading rounds_heading = f"\n*** Round {rounds_played + 1} of {num_rounds} ***" print(rounds_heading) print(patai_list[rounds_played]) user_choice = string_checker(options_list[rounds_played], answer_list) # Random computer choice result = rps_compare(user_choice, answer_list[rounds_played]) # Add counters for the result and the game history if result == "correct": rounds_won += 1 feedback = "\U0001F607 \U0001F929 Correct! \U0001F929 \U0001F607" else: rounds_lost += 1 feedback = f"*** Incorrect! *** The correct answer is {answer_list[rounds_played]}" history_item = f"Round: {rounds_played + 1} - {feedback}" print(feedback) game_history.append(history_item) rounds_played += 1 # Calculate stats rounds_won = rounds_played - rounds_lost percentage_won = rounds_won / rounds_played * 100 percentage_lost = rounds_lost / rounds_played * 100 # Display Game Stats print() print("**** Quiz STATS ****") print(f"You won {rounds_won} out of {rounds_played} rounds") print(f"Won: {percentage_won:.2f} % \t" f"Lost: {percentage_lost:.2f} % \t") print() # Quiz history option see_history = string_checker("Do you want to see your game history? ", yes_no) if see_history == "YES": for item in game_history: print(item) # End of program message print() print("The Quiz has ended")