python连载第11篇 if 语句

#python连载第11篇 if 语句
#if单个选择测试,两个print是一个代码块,所以都要执行
age = 17
if age > 10:
    print("you are old enough to enjoy love with TA")
    print("you can do some wonderful things")


#if一个测试,多个选择语句例子
age = 150
if age < 50:
    print("the train ticket is free")
elif age == 50:
    print("the train ticket is free")
elif age < 120:
    print("the train ticket is half price")
elif age == 120:
    print("the train ticket is half price")
else:
    print("the train ticket is full price")     #身高大于120cm,所以全价票
#if 嵌套
num = int(input("please input an integer:"))    
if num%5 == 0:
    if num%6 == 0:
        print ("the number you input can be exact divided by  5 and 6")
    else:
        print ("the number you input can be exact divided by  5,but not by 6")
else:
    if num%6 == 0:
        print ("the number you input can be exact divided by  6,but not by 5")
    else:
        print  ("the number you input can not be exact divided by 5 and 6")



2017-11-26 16:56:48 November Sunday the 47 week, the 330 day
#if的例子,检查字符串
if 'python' == 'Python':
    print("'python' == 'Python'")
else:
    print("'python' != 'Python'")       #不相等哈,字母有大小写分别
if 'love' in "I love you":              #in 包含的意思,一个小东西是否在大东西里面
    print("'love' is in 'I love you'")
else:
    print("'love' is not in 'I love you'")

if 'leben' not in "I love you":         #not in 不包含的意思,小数据是否不在大数据里
    print("'leben' is not in 'I love you'")
else:
    print("'leben' is in 'I love you'")
#检查数字:
if 10 <= 6:
    print("10 <= 6 is true")
else:
    print("10 <= 6 is false")
#检查多个条件
if 10 > 6 and 10 >9:            #and 代表并且,两个条件都成立才是真
    print('10 > 6 and 10 >9 is true')
else:
    print("10 > 6 and 10 >9 is false")

if 10 > 6 or 10 < 9:            #or代表或,有一个条件成立就是真
    print('10 > 6 or 10 >9 is true')
else:
    print("10 > 6 or 10 >9 is false")


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值