我目前正在编写一些代码,我是一名研究检疫的学生,我正试图解决一个圣诞树的问题,但不能完全理解它
圣诞树必须用“while”完成,我已经试过了,但我只得到了一半
代码行:
lines=1
maxlines=9
while lines>=maxlines:
print (lines*'*')
lines+=1
我得到的是:
*
**
***
****
*****
******
*******
********
*********
我想要的是:
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
给你。这将打印树
首先,您的代码无法工作,因为在while循环中
lines
永远不会大于maxlines
,所以语句是False
正如所有其他人提到的,您缺少空格。另一种尽可能接近代码的方法是:
其中:
相关问题 更多 >
编程相关推荐