小甲鱼Python第七讲课后习题

0.if not(money < 100):上边这行代码相当于?

if money>=100

 

1.assert 的作用是什么?

assert “断言”,当这个关键字后边的条件为假的时候,程序自动崩溃并抛出 AssertionReeor

 

2.假设有x=1,y=2,z=3,请问如何快速将三个变量的值相互交换?

x,y,z=1,2,3

x,y,z=z,y,x

print(x,y,z)

 

3.你听说过成员资格运算符吗?

Python 有一个成员资格运算符:in,用于检查一个值是否在序列中,如果在序列中返回True,否则返回False
>>> name ="小甲鱼"
>>> '鱼' in name
True
>>> '哈哈' in name
False

 

动手

0.按照100分制,90分以上成绩为A,80到90为B,70到80为C,60到70为D,其余为不及格

注意:三元操作符   small = x if x < y else y

自己写的代码还是很Low

while True:
temp=input("chengji")
while temp.isspace() or not temp.isdigit():
temp =input("chongxinshuruchengji")
a=int(temp)
if a>=90:
print('A')
elif a>=80 and a<90:
print('B')
elif a>=70 and a<80:
print('C')
elif a>=60 and a<70:
print('D')
else:
print('不及格')
附加:
temp = input("请输入分数:")
score = int(temp)
while score > 100 or score <0:
    temp = input("输入错误,请重新输入")
    score = int(temp)
if 90 <= score <= 100:
    print("A")
elif 80 <= score < 90:
    print("B")
elif 70 <= score < 80:
    print("C")
elif 60 <= score <70:
    print("D")
else:
    print("不及格")

1.转换成三元操作符

x,y,z =6,5,4

if x<y:

  small=x

  if z<small:

    small=z

elif y<z:

  small=y

else:

  small=z

 

small = x if x<( y if y<z else z) else ( y if y<z else z)

转载于:https://www.cnblogs.com/jieperhaps/p/9003234.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值