1.less.py (half-pyramid)
from cs50 import get_int
# prompt user to input the height
height = get_int("height:")
while height <= 0 or height > 8:
height = get_int("invalid input,only allowed (0-8)height:")
for f in range(0, height):
# do something with f
for i in range(f + 1, height):
print(' ', end='')
for j in range(height, (height - 1) - f, -1):
print('#', end='')
print('')
2.more.py (pyramid)
from cs50 import get_int
# prompt user to input height
height = get_int("height:")
while height <= 0 or height > 8:
height = get_int("invalid input,only allowed(0-8) height:")
for f in range(0, height):
for i in range(f + 1, height):
print(' ', end='')
for j in range(height, (height - 1) - f, -1):
print('#', end='')
print(' ', end='')
for k in range(height, (height - 1) - f, -1):
print('#', end='')
print('')
3.思路
1.从上到下,从左到右
2.空格看不出效果先用.
或者其他的占位子
3.观察不同符号的个数变化,一直增加or一直减少or…
4.注意什么时候不需要换行end=''
5.缩进最重要!!!