pattern = input("请输入你要选择的模式:") while True: if pattern == "A": row = eval(input("请输入行数:")) for i in range(1, row + 1): for j in range(1, i+1): print(j, end=" ") print("") elif pattern == "B": row = eval(input("请输入行数:")) for i in range(1, row + 1): for j in range(1, row - i + 2): print(j, end=" ") print("") elif pattern == "C": row = eval(input("请输入行数:")) for i in range(1, row + 1): for j in range(row - i, 0, -1): print(" ", end=" ") for j in range(i, 0, -1): print(j, end=" ") print("") elif pattern == "D": row = eval(input("请输入行数:")) for i in range(1, row + 1): for j in range(1, i): print(" ", end=" ") for j in range(1, row - i + 2 ): print(j, end=" ") print("") elif pattern == "退出": break else: pattern = input("输入错误,请从新输入")