
- 学习Python分支结构
- 单分支
- 双分支
- 多分支
# -*- coding: utf-8 -*-
"""
功能:判断令狐冲大侠喝酒杯数
作者:zwh
日期:2021年11月4日
"""
print('令狐大侠说他喝了若干杯酒,
杯数满足条件:三三数之剩二,
五五数之剩三,七七数之剩二,
问令狐大侠究竟喝了多少杯酒?')
cups = int(input('你认为令狐大侠喝了几杯?请输入杯数:'))
if cups % 3 == 2 and cups % 5 == 3 and cups % 7 == 2:
print('朋友,你说对了,令狐大侠确实喝了{}杯酒!'.format(cups))
双分支
# -*- coding: utf-8 -*-
"""
功能:判断令狐冲大侠喝酒杯数
作者:zwh
日期:2021年11月4日
"""
print('令狐大侠说他喝了若干杯酒,
杯数满足条件:三三数之剩二,
五五数之剩三,七七数之剩二,
问令狐大侠究竟喝了多少杯酒?')
cups = int(input('你认为令狐大侠喝了几杯?请输入杯数:'))
if cups % 3 == 2 and cups % 5 == 3 and cups % 7 == 2:
print('朋友,你说对了,令狐大侠确实喝了{}杯酒!'.format(cups))
else:
print('朋友,你说错了,令狐大侠并没有喝{}杯酒!'.format(cups))
多分支
# -*- coding: utf-8 -*-
"""
功能:并列式多分支评定成绩等级
作者:zwh
日期:2021年11月4日
"""
# 输入部分
score = float(input('score = '))
# 处理部分
level = ''
if score > 100 or score < 0:
level = '超出范围'
elif score >=90:
level = '优秀'
elif score >= 80:
level = '良好'
elif score >= 70:
level = '中等'
elif score >= 60:
level = '及格'
else:
level = '不及格'
# 输出部分
print('等级:{}'.format(level))``
# -*- coding: utf-8 -*-
"""
功能:并列式多分支评定成绩等级
作者:zwh
日期:2021年11月4日
"""
# 输入部分
score = float(input('score = '))
# 处理部分
level = ''
if score > 100 or score < 0:
level = '超出范围'
else:
if score < 60:
level = '不及格'
else:
if score < 70:
level = '良好'
else:
if score < 80:
level = '良好'
else:
if score < 90:
level = '中等'
else:
if score <= 100:
level = '优秀'
# 输出部分
print('等级:{}'.format(level))
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)