import random def string_checker(question, valid_ans=("yes", "no")): error = f"Please enter a valid option from the following list: {valid_ans}" while True: # get user response and make sure it's lowercase user_response = input(question).lower() for item in valid_ans: # check if the user response is a word in the list if item == user_response: return item # check if the user response is the same as # the first letter of an item in the list elif user_response == item[0]: return item # print error if user does not enter something that is valid print(error) print() def int_check(question): while True: to_check = input(question) # Check for infinite mode if to_check == "": return "infinite" try: response = int(to_check) # Check that the number is more than or equal to 1 if response < 1: print("Please enter an integer that is 1 or more.") else: return response except ValueError: print("Please enter a valid integer or press Enter for infinite mode.") # def instruction is the variable for the instructions def instructions(): instruction = """ Perimeter and Area Quiz Instructions Welcome to the Perimeter and Area Quiz! This program is designed to help you understand and practice calculating the perimeter and area of different shapes. It is suitable for intermediate students or anyone looking to improve their skills in this area. How it Works: 1. Introduction: The quiz begins with a brief overview of the formulae for calculating the perimeter and area of squares, triangles, and rectangles. Additionally, it will explain the rules for answering the questions. 2. Mode Selection: You will have the option to choose between: - Infinite Mode: Answer an unlimited number of questions. - Set Round: Answer a fixed number of questions. 3. Quiz: You will be presented with questions where you need to calculate the perimeter or area of a given shape. Enter your answers based on the provided shapes. 4. Exit and History: After completing the quiz, you can choose to exit the program. You will then have the option to view your game history to see your performance. Good luck, and have fun learning! """ print(instruction) print("📚 Area and Perimeter quiz 📚") print() # these variable prints the question want_instructions = string_checker("Do you want to read the instructions?") # checkers users enter yes (Y) or no (N) if want_instructions == "yes": instructions() # Ask user for number of rounds / infinite mode num_rounds = int_check("How many rounds would you like? Push for infinite mode: ") if num_rounds == "infinite": mode = "infinite" num_rounds = 5 shape_list = ["square", "rectangle", "triangle"]