• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

Python多分支if语句的使用

python 搞代码 4年前 (2022-01-09) 32次浏览 已收录 0个评论

注意:if语句代码是从上往下执行的,当执行到满足条件的语句时,代码会停止往下执行

注意:if语句后面要加上冒号

score = int (input("score:"))
if score > 90:
  print("A")
elif score > 80:
  print("B")
elif score > 70:
  print("C")
elif score > 60:
  print("D")
else score < 60:
  print("加油吧孩纸")

补充知识:python之if语句以及条件测试( and 、or、in、not in)

1.and 、or、in、not in

'''
条件测试
'''
#单个条件测试
age0 = 22
print(age0>=22) # True

#多个条件测试 and
age0 = 22
age1 = 18
print(age0>=21 and age1>=21) #False

#多个条件测试 or
print(age0>=21 or arg0>=21) #True
 
#in和not in(检查特定值是否在列表中)
fruits = ['apple','banana','orange']
print('apple' in fruits) #True
print('apple' not in fruits) #False

2.

本文来源gaodai^.ma#com搞#代!码网

if语句

'''
简单的if语句(仅包含一个测试和一个操作)
'''
height = 1.7
if height>=1.3:
  print('高')
'''
if-else
'''
height = 1.8
if height<=1.4:
  print('免票')
else:
  print('全票')
#最后输出全票
'''
if-elif
'''
height = 1.5
if height>=1.4:
  print('嘿嘿')
elif height>=1.3:
  print('呵呵')
#最后输出嘿嘿
'''
if-elif-else
'''
height = 1.8
if height<=1.4:
  print('免票')
elif height>1.4 and height<=1.7:
  print('半票')
else:
  print('全票')
#最后输出全票

以上这篇Python多分支if语句的使用就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:Python多分支if语句的使用
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址