码迷,mamicode.com
首页 > 其他好文 > 详细

流程控制之if判断

时间:2020-03-06 15:27:02      阅读:47      评论:0      收藏:0      [点我收藏+]

标签:==   嵌套   star   beautiful   一起   流程   改进   开始   pre   

‘‘‘
语法1:
if 条件:
代码1
代码2
代码3

‘‘‘
# age = 60
# is_beautiful = True
# star = ‘水平座‘
#
# if age > 16 and age < 20 and is_beautiful and star == ‘水平座‘:
# print(‘我喜欢,我们在一起吧。。。‘)
#
# print(‘其他代码.............‘)


‘‘‘
语法2:
if 条件:
代码1
代码2
代码3
else:
代码1
代码2
代码3
‘‘‘

# age = 60
# is_beautiful = True
# star = ‘水平座‘
#
# if age > 16 and age < 20 and is_beautiful and star == ‘水平座‘:
# print(‘我喜欢,我们在一起吧。。。‘)
# else:
# print(‘阿姨好,我逗你玩呢,深藏功与名‘)
#
# print(‘其他代码.............‘)


‘‘‘
语法3:
if 条件1:
代码1
代码2
代码3
elif 条件2:
代码1
代码2
代码3
elif 条件2:
代码1
代码2
代码3
‘‘‘
# score=73
# if score >= 90:
# print(‘优秀‘)
# elif score >= 80 and score < 90:
# print(‘良好‘)
# elif score >= 70 and score < 80:
# print(‘普通‘)

# 改进
# score = input(‘请输入您的成绩:‘) # score="18"
# score=int(score)
#
# if score >= 90:
# print(‘优秀‘)
# elif score >= 80:
# print(‘良好‘)
# elif score >= 70:
# print(‘普通‘)


‘‘‘
语法3:
if 条件1:
代码1
代码2
代码3
elif 条件2:
代码1
代码2
代码3
elif 条件2:
代码1
代码2
代码3
...
else:
代码1
代码2
代码3
‘‘‘
# score = input(‘请输入您的成绩:‘) # score="18"
# score=int(score)
#
# if score >= 90:
# print(‘优秀‘)
# elif score >= 80:
# print(‘良好‘)
# elif score >= 70:
# print(‘普通‘)
# else:
# print(‘很差,小垃圾‘)
#
# print(‘=====>‘)


‘‘‘
if嵌套if
‘‘‘
age = 17
is_beautiful = True
star = ‘水平座‘

if 16 < age < 20 and is_beautiful and star == ‘水平座‘:
print(‘开始表白。。。。。‘)
is_successful = True
if is_successful:
print(‘两个从此过上没羞没臊的生活。。。‘)
else:
print(‘阿姨好,我逗你玩呢,深藏功与名‘)

print(‘其他代码.............‘)

流程控制之if判断

标签:==   嵌套   star   beautiful   一起   流程   改进   开始   pre   

原文地址:https://www.cnblogs.com/h1227/p/12426226.html

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