2018-04-03 python条件控制

Python的if while for
 缩进格式
冒号


If条件判断


if 判断条件:
执行语句
elif 判断条件:
执行语句
else:
执行语句
 while


While 判断条件:
执行语句

break        跳出循环
continue 跳到下一次循环

缩进&& 冒号

for i in range(1, 10):
    print(i)

1
2
3
4
5
6
7
8
9

if条件

if条件语句是通过一条或多条语句的执行结果(True或者False)来决定执行


age = input("Please input your age: ")
# print(type(age))
if age.strip():
    if age.isdigit():
        if int(age)>=18:
            print("你是一个成年人!")
        else:
            print("你还是一个小屁孩!")
    else:
        print("你输入的不是数字")
else:
    print("你输入的只有空格")

Please input your age: 12
你还是一个小屁孩!

Please input your age: 22
你是一个成年人!


while循环


while循环
# while 条件判断:
#     逻辑操作


a = 100
while a >= 1:
    print(a)
    a -= 1

score = 59
while True:
    if score > 60:
        print("恭喜你及格了!")
    else:
        print("菜逼,等着补考吧!")


乘法口诀

for b in range(1, 10):
    for a in range(1, b+1):
        print("{0}x{1}={2}".format(a, b, a*b), end=" ")
        if a == b:
            print()

1x1=1 
1x2=2 2x2=4 
1x3=3 2x3=6 3x3=9 
1x4=4 2x4=8 3x4=12 4x4=16 
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25 
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30 6x6=36 
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35 6x7=42 7x7=49 
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40 6x8=48 7x8=56 8x8=64 
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45 6x9=54 7x9=63 8x9=72 9x9=81 






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值