import random # generates the area question def area_question_generator(): shapes = ["rectangle", "square"] shape = random.choice(shapes) if shape == "rectangle": width = random.randint(2, 24) length = random.randint(2, 24) unit = random.choice(["cm", "m", "km"]) area_question = f"Area of a rectangle with width of {width}{unit} and a length of {length}{unit}" area_answer = width * length else: # square side = random.randint(2, 24) unit = random.choice(["cm", "m", "km"]) area_question = f"Area of a square with a {side}{unit} side" area_answer = side * side return area_question, area_answer, unit question, answer, unit = area_question_generator() print(question) print(f"The answer is {answer}") print(unit)