下面是一个绘制数字树的程序,但我无法避免“if”语句
# -*- coding: cp1252 -*-
import sys
def xmasTree():
centre=35
inicial=1
level=input("¿Triangle height? \n\t")
for height in range (inicial,level+1):
for index in range(1,centre-height):
sys.stdout.write(' ')
sys.stdout.write(str(inicial))
for index in range(inicial+1,height):
sys.stdout.write(str(index))
for index in range(height,inicial,-1):
sys.stdout.write(str(index))
if height>1:
sys.stdout.write('1')
sys.stdout.write('\n')
xmasTree()
*编辑:我终于找到了我想要的。显然我没有正确地解释自己。无论如何,谢谢大家!在
以下是正确的代码:
^{pr2}$以及正确的输出:
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654321
输出
^{pr2}$递归函数:
相关问题 更多 >
编程相关推荐