美文网首页
python——if...elif...和三元条件表达和asse

python——if...elif...和三元条件表达和asse

作者: ELLENXX | 来源:发表于2019-06-29 10:08 被阅读0次

if....elif....

score=int(input('输入你的成绩:'))
if 100>score and score>=90:
    print('you are A')
elif 90>score and score >=80:
    print('you are B')
elif 80>score and score >=70:
    print('you are C')
elif 80>score and score >=60:
    print('you are D')
else:print('重修吧!')

三元条件表达

if x<y:
    small=x
else:
    small=y
print(small)

等价于

x,y=6,2
small=x if x<y else y
print(small)

assert

assert这个关键字我们称为断言,当这个关键字后面的条件为假的时候,程序自动崩溃并抛出AssertionError的异常

assert 3>4

Traceback (most recent call last):
File "......", line 1, in <module>
assert 3>4
AssertionError

我们可以利用assert程序中加入检查点,只有满足assert后面的条件的时候才能让程序正常工作

相关文章

网友评论

      本文标题:python——if...elif...和三元条件表达和asse

      本文链接:https://www.haomeiwen.com/subject/oovucctx.html