一、if判断语句
if语句是用来进行判断的,其使用格式如下:
![](https://ask.qcloudimg.com/http-save/yehe-8223537/9488f322be4aeb2d676141e0af43d422.png)
if 要判断的条件:
条件成立时,要做的事情
else 这里写代码片否者
要做的事情
二、框图
三、参考代码:
chePiao = 1
if chePiao == 1:
print("hell")
else:
print("hell word")
四、elif
if xxx1:
事情1
elif xxx2:
事情2
elif xxx3:
参考代码:
score = 77
if score>=90 and score<=100:
print('本次考试,等级为A')
elif score>=80 and score<90:
print('本次考试,等级为B')
elif score>=70 and score<80:
print('本次考试,等级为C')
elif score>=60 and score<70:
print('本次考试,等级为D')
elif score>=0 and score<60:
print('本次考试,等级为E')
五、与else一起使用
参考代码:
num = 3
if num>=5:
print('good')
elif ((num<5) and (num>=3)):
print('secondary')
else:
print('wanting')
六、if的嵌套
chePiao = 1 # 用1代表有车票,0代表没有车票
daoLenght = 9 # 刀子的长度,单位为cm
if chePiao == 1:
print("有车票,可以进站")
if daoLenght < 10:
print("通过安检")
print("终于可以见到Ta了,美滋滋~~~")
else:
print("没有通过安检")
print("刀子的长度超过规定,等待警察处理...")
else:
print("没有车票,不能进站")
print("亲爱的,那就下次见了,一票难求啊~~~~(>_<)~~~~")
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/hz/148087.html