import random # generates the area question def perimeter_gen(): shapes = ["rectangle", "square"] shape = random.choice(shapes) if shape == "rectangle": width = random.randint(2, 36) height = random.randint(2, 36) unit = random.choice(["cm", "m"]) perimeter_question = f"The Perimeter of a rectangle with width of {width}{unit} and a length of {height}{unit}" perimeter_answer = 2 * (width + height) else: # square side = random.randint(2, 36) unit = random.choice(["cm", "m"]) perimeter_question = f"The Perimeter of a square with a {side}{unit} side" perimeter_answer = 4 * side return perimeter_question, perimeter_answer question, answer = perimeter_gen() print(question) print(f"The answer is {answer}")