"""条件表达式"""
#案例一:
a = 3
b = 4
#if语句
if a<b:
small = a
else:
small = b
print(small)
#条件表达式
small = a if a < b else b
print(small)
#案例二:
score = int(input())
#if语句
if score == 100:
print("S")
elif score >= 90:
print("A")
elif score >= 80:
print("B")
elif score >= 60:
print("C")
elif score >= 0:
print("D")
else:
print("请输入0~100之间的数字")
#条件表达式
(print("S") if score == 100 else print("A")
if score >= 90 else print("B")
if score >= 80 else print("C")
if score >= 60 else print("D")
if score >= 0 else print("请输入0~100之间的数字"))
#用括号扩起来,表示括号里的是一个语句,方便换行
Python 条件表达式
猜你喜欢
转载自blog.csdn.net/look_outs/article/details/127701692
今日推荐
周排行