码迷,mamicode.com
首页 > 编程语言 > 详细

python语句

时间:2018-12-03 12:52:35      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:span   div   color   ror   welcome   if...else   python语句   man   输出   

基本逻辑运算符(if ...elif...else)(0,False,None为假)

flag = False
name = luren
if name == python:         # 判断变量否为‘python‘
    flag = True          # 条件成立时设置标志为真
    print(welcome boss)    # 并输出欢迎信息
else:
    print(name)              # 条件不成立时输出变量名称
 1 num = 5     
 2 if num == 3:            # 判断num的值
 3     print(boss)        
 4 elif num == 2:
 5     print(user)
 6 elif num == 1:
 7     print(worker)
 8 elif num < 0:           # 值小于零时输出
 9     print(error)
10 else:
11     print(roadman)     # 条件均不成立时输出
 1 num = 9
 2 if num >= 0 and num <= 10:    # 判断值是否在0~10之间
 3     print(hello)
 4 # 输出结果: hello
 5  
 6 num = 10
 7 if num < 0 or num > 10:    # 判断值是否在小于0或大于10
 8     print(hello)
 9 else:
10     print(undefine)
11 # 输出结果: undefine
12  
13 num = 8
14 # 判断值是否在0~5或者10~15之间
15 if (num >= 0 and num <= 5) or (num >= 10 and num <= 15):    
16     print(hello)
17 else:
18     print(undefine)
19 # 输出结果: undefine
age = 16
high = 170
success = True

if age:
    print(ok)
else:
    print(不OK)

if age > 17:
    if success:
        print(咱们结婚吧!)
    else:
        print(去他妈的爱情!)
elif high > 160:
    print(你好高)
else:
    print(不表白)
 score=input(>>: )
 > 90:优秀
 80 < 90 :良好
 >=60 <80 :合格
 <60:滚犊子


 score = int(input(请输入你的成绩:))
 if score > 90:
     print(优秀)
 elif score > 80 and score <= 90:
     print(良好)
 elif score >=60 and score < 80:
     print(合格)
 else:
     print(滚犊子)

 

python语句

标签:span   div   color   ror   welcome   if...else   python语句   man   输出   

原文地址:https://www.cnblogs.com/wangxudong/p/10057604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!