psets6 mario.py

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.缩进最重要!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值