我想在 python 中创建一棵圣诞树,层和基不随机,只打印圣诞节例如,如果我输入数字 3,程序应该打印:我想这样输出 * *** * *** ***** * *** ***** ******* | ===V===代码: a = int(input(''))for i in range(a, 0, -1): for j in range(0, 5): print(end=' ') for f in range(0, i): print(end=' ') for h in range(0, 2 * (a - i) + 1): print('*', end='')print()b = a + 1for i in range(b, 0, -1): for j in range(0, 2): print(end=' ') for f in range(0, i): print(end=' ') for h in range(0, (2 * (b - i) + 1)): print('*', end='')print()c = a + 2for i in range(c, 0, -1): for j in range(0, 1): print(end=' ') for f in range(0, i): print(end=' ') for h in range(0, (2 * (c - i) + 1)): print('*', end='')print()d = a + 3for i in range(d, 0, -1): for f in range(0, i): print(end=' ') for h in range(0, (2 * (d - i) + 1)): print('*', end='')print()它不起作用,因为当我运行此代码程序时,它会像这样打印 * *** ***** * *** ***** ******* * *** ***** ******* ********* * *** ***** ******* ********* ***********我不知道你为什么要帮我?
1 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
尝试这个:
n = int(input())
addSpace = 4
for i in range(1, n+1):
left = " "*(n-i+addSpace)
for j in range(i+1):
print(left+" "*(i-j)+"*"*(2*j+1))
print(" "*(n+addSpace) + "|")
print(" "*addSpace + "="*n + "V" + "="*n)
添加回答
举报
0/150
提交
取消