2 回答
第一题:
第二题:
第三题:
代码
while True: n = int(input("请输入一个正整数:")) if n%2!=0: for each in range(1, n+1): num_1 = (n + 1) / 2 - each if num_1 >= 0: num_2 = 2 * each - 1 else: num_1 = -num_1 temp = (n + 1) / 2 num_2 = (2 * temp - 1) - 2 * (each - temp) print(int(num_1)*" "+int(num_2)*str(each)) else: cont_n1 = [] cont_n2 = [] cont_n3 = range(int(n/2)+1, n+1) for each in range(1, int(n/2)+1): num_1 = n/2 - each cont_n1.append(num_1) num_2 = 2 * each - 1 cont_n2.append(num_2) print(int(num_1) * " " + int(num_2) * str(each)) cont_n1.reverse() cont_n2.reverse() for each_1, each_2, each_3 in zip(cont_n1, cont_n2, cont_n3): print(int(each_1) * " " + int(each_2) * str(each_3))
举报
0/150
提交
取消