Lecture 008: Awesome Branches and Loops 02

Class content

1. Determine the level of each grade

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('score'))

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. Ternary operator:

x= 4, y=5

if x < y 

 small = x:

else

small = y

small = x if x < y else y (if the value of x < y is expected to be true, small is equal to x; otherwise small is equal to y)

3. assert assertion:

If the condition after assert is false, the program automatically crashes with an AssertionError

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325215150&siteId=291194637