选择结构学习

多分支结构

并列式多分支结构

# -*- coding: utf-8 -*-
"""
功能:并列式多分支结构
作者:CXF
时间:2021年11月4日
"""

# 输入部分
score =float(input('score ='))
# 处理部分
level = ''
if score > 100:
    level = '超出范围'
if score >= 90 and score <= 100:
    level = '优秀'
if score >= 80 and score < 90 :
    lecel = "良好"
if score >= 70 and score < 80:
    level = '中等'
if score >= 60 and score < 70:
    level = '及格'
if score >= 0 and score < 60:
    level = '不及格'
if score < 0:
    level = '超出范围'
# 输出部分
print('等级为{}'.format(level))

嵌套式多分支结构

# -*- coding: utf-8 -*-
"""
功能:嵌套式多分支结构
作者:CXF
时间:2021年11月4日
"""

# 输入部分
score =float(input('score ='))
# 处理部分
level = ''
if score > 100:
    level = '超出范围'
else:
    if score >=90:
        level = "优秀"
    else:
        if score >= 80:
            level = "良好"
        else:
            if score >= 70:
                level ="中等"
            else:
                if score >= 60:
                    level ="及格"
                else:
                    if score >=0:
                        level = "不及格"
                    else:
                        level ="超出范围"
# 输出部分
print('等级为{}'.format(level))

延拓式多分支结构

# -*- coding: utf-8 -*-
"""
功能:延拓式多分支结构
作者:CXF
时间:2021年11月4日
"""

# 输入部分
score =float(input('score ='))
# 处理部分
level = ''
if score > 100:
    level = "超出范围"
elif score >= 90:
    level = "优秀"
elif score >= 80:
    level = "良好"
elif score >= 70:
    level = "中等"
elif score >= 60:
    level = "及格"
elif score >= 0:
    level = "不及格"
else:
    level = "超出范围"
# 输出部分
print('等级为{}'.format(level)) 

猜你喜欢

转载自blog.csdn.net/qq_62590351/article/details/121149156