栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

2021/11/4单分支、多分支机构

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

2021/11/4单分支、多分支机构

文章目录
  • 学习Python分支结构
      • 单分支
      • 双分支
      • 多分支

学习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))![请添加图片描述](https://img-blog.csdnimg.cn/1f8dab4a36df423aa5d300ec1e758dcc.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAemwyMDIxMTE=,size_20,color_FFFFFF,t_70,g_se,x_16)

双分支

# -*- 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))
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/444371.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号