第 008讲:了不起的分支和循环02
课堂内容
1. 判断各个成绩段的级别
score = int(input ("成绩"))
if 90 <= score <= 100:
print ('A')
elif 80 <score <=90:
print ('B')
elif 70<score <=80:
print ('C')
elif 0<score <=60:
print ('D')
score = int(input ('成绩'))
if 100>= score >= 90:
print ('A')
elif 90> score >= 80:
print ('B')
elif 80> score >= 60:
print ('C')
elif 60> score >= 0:
print ('D')
2. 三元操作符:
x= 4, y=5
if x < y
small = x:
else
small = y
small = x if x <y else y (如果想x<y的值是真的,small等于x; 否则small等于y)
3. assert 断言:
if assert后面的条件是假,程序自动崩溃并抛出AssertionError