python之流程控制if判断

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

age = 18
is_beautiful = True
star  = '水瓶座'
if age > 16 and age < 20 and is_beautiful and star == '水瓶座':
	print('我喜欢你,我们在一起吧')
print('byebye~')

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

age = 60
is_beautiful = True
star = '水瓶座'
if age > 16 and age < 20 and is_beautifu  and star == '水瓶座':
	print('我喜欢你爱,我们在一起吧')
else:
	print(‘阿姨好,我逗你玩呢,深藏功与名’)

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

score = input('your score:')
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 条件3:
代码1
代码2
代码3
else:
代码1
代码2
代码3

 score = input ('请输入你的成绩:')
 score = int(score)
 if score >= 90:
 	print('A')
 elif score >= 80:
 	print('B')
 elif score >= 70:
 	print('C')
 else:
 	print('D')

if 嵌套

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

猜你喜欢

转载自blog.csdn.net/weixin_47237915/article/details/114289213