09.分支结构

一、双分支结构 

#双分支结构
'''if...else...二选一执行'''
num=int(input('请输入一个整数'))
if num%2==0:
    print(num,'是偶数')
else:
    print(num,'是奇数')

二、多分支结构

多分支结构,多选一执行
从键盘录入一个整数 成绩
分为A,B,C,D,E等级,小于0或大于100为非法数据

score=int(input('请输入一个成绩:'))
if score>=90 and score<=100:
    print('A级')
elif score>=80 and score<90:
    print('B级')
elif score>=70 and score<80:
    print('C级')
elif score>=60 and score<70:
    print('D级')
elif score>=0 and score<60:
    print('E级')
else:
    print('对不起,成绩有误,不在有效成绩内')

在python中,
score>=90 and score<=100  可以写为  90<=score<=100

三、嵌套if的使用

会员 >=200 8折
>=100 9折
不打折
非会员 >=200 9.5折
不打折

answer=input('您是会员吗?y/n')
money=float(input('购买的总金额为'))
if answer=='y':
    print('会员')
    if money>=200:
        print('打八折,付款金额为:',money*0.8)
    elif money>=100
        print('打九折,付款金额为:',money * 0.9)
    else:
        print('不打折,付款金额为:',money)
else:
    print('非会员')
    if money>=200:
        print('打九五折,付款金额为:',money*0.95)
    else:
        print('不打折,付款金额为:',money)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值