我用 C++ 编写了一个显示星号金字塔的程序(见下文),现在我想看看它是如何用 Python 完成的,但它并不像我想象的那么容易。
有没有人试过这个,如果试过,你能告诉我有用的代码吗?
提前致谢。
*
***
*****
*******
*********
***********
*************
***************
最佳答案
def pyramid(rows=8):
for i in range(rows):
print ' '*(rows-i-1) + '*'*(2*i+1)
pyramid(8)
*
***
*****
*******
*********
***********
*************
***************
pyramid(12)
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*********************
***********************
关于python - Python 星号金字塔程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4911341/