num = eval(input("请输入一个整数:")) for i in range(1, num + 1): for j in range(num-i, 0, -1): print(" ", end=" ") for j in range(i, 1, -1): print(j, end=" ") for j in range(1, i+1): print(j, end=" ") print(" ")
row = int(input("请输入行数:")) num = 1 sum = 0 for i in range(1, row + 1): for j in range(row - i, 0, -1): print(" ", end=" ") for j in range(1, i + 1): print(num, end=" ") num *= 2 sum = num num = 1 sum //= 2 for j in range(2, i + 1): print(sum//2, end=" ") sum //= 2 print("")
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("输入错误,请从新输入")