import random # V2 improve headings, instructions and options to select the number of questions (min 5, max 10) # add 5 more questions, add a rating using the number of correct answers # 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).lower() 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 questions (minimum is 5, maximum is 10). When the question displays, enter the letter that you think matches the answer. If an invalid letter is entered a helpful hint will be displayed. ''' ) # compare the correct answer v the user input # result - correct or incorrect def rps_compare(user, answer): if user == answer: round_result = "correct" else: round_result = "incorrect" return round_result # checks the input is an integer def int_check(question, low, high): while True: error = f"Enter a number between {low} and {high}" to_check = input(question) try: response = int(to_check) # check the number is between the min and max numbers if low <= response <= high: return response else: print(error) except ValueError: print(error) # Main routine # quiz variables rounds_played = 0 incorrect_answer = 0 correct_answer = 0 yes_no = ["yes", "no"] abcd_list = ['a', 'b', 'c', 'd'] 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?", "What is the Māori new year known as?", "Who is the Māori god of the forest?", "What is the traditional Māori cloak made of flax fibers called?", "What is the traditional Māori food?", "What the traditional Māori skin markings called?", "What is a Māori greeting?"] answer_list = ['a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'a', 'b'] 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", "A. Matariki\nB. Tupuānuku\nC. Waitā\nD. Tupuārangi\n", "A. Ranginui\nB. Tāne-mahuta\nC. Tangaroa\nD. Rongomātāne\n", "A. Muka\nB. Kākahu\nC. Korowai\nD. Tarau\n", "A. Tuna\nB. Kereru\nC. Waitī\nD. Hangi\n", "A. Tā Moko\nB. Mokopuna\nC. Kirituhi\nD. Ururangi\n", "A. Ka kite\nB. Kia ora\nC. Haere ra\nD. Kaupapa\n"] 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 questions, 5 is the minimum, 10 is the maximum ", 5, 10) # game loop starts here while rounds_played < num_rounds: # Heading questions_heading = f"\n*** Question {rounds_played + 1} of {num_rounds} ***" print(questions_heading) print(patai_list[rounds_played]) user_choice = string_checker(options_list[rounds_played], abcd_list) # Random computer choice result = rps_compare(user_choice, answer_list[rounds_played]) # Add counters for the result and the quiz history if result == "correct": correct_answer += 1 feedback = "\U0001F607 \U0001F929 Kei te tika! \U0001F929 \U0001F607" else: incorrect_answer += 1 feedback = f"*** Kei te he *** The correct answer is {answer_list[rounds_played].upper()}" print(feedback) rounds_played += 1 # Calculate stats correct_answer = rounds_played - incorrect_answer percentage_won = correct_answer / rounds_played * 100 percentage_lost = incorrect_answer / rounds_played * 100 # Display Quiz Stats print() print("**** QUIZ STATS ****") print(f"You won {correct_answer} out of {rounds_played} rounds") print(f"Won: {percentage_won:.2f} % \t" f"Lost: {percentage_lost:.2f} % \t") print() # Quiz ratings print("**** QUIZ FEEDBACK ****") if correct_answer == num_rounds: print("Ka rawe! - Excellent!") elif num_rounds - 1 >= correct_answer >= num_rounds - 2: print("Tōna pai nei - Not bad") else: print("Aue! Ka aroha - How sad") # End of program message print() print("The Quiz has ended")