我想在 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 + 1
for 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 + 2
for 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 + 3
for 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()
它不起作用,因为当我运行此代码程序时,它会像这样打印
*
***
*****
*
***
*****
*******
*
***
*****
*******
*********
*
***
*****
*******
*********
***********
我不知道你为什么要帮我?
繁华开满天机
相关分类