本文最后更新于 2022-05-26 11:25:30
codeStructure
if-else
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| score = int(input("请输入分数:\n"))
if score > 100 or score < 0: print("error input") elif score >= 90 and score <= 100: print("A") elif 80 <= score < 90: print("B") elif 70 <= score < 80: print("C") else: print("D")
|
嵌套
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| vip = bool(input("是不是会员\n")) prise = int(input("价格\n"))
if vip: if prise>100: print("9折") else: print("9.5折") else: print("不打折")
|
简化if-else
1 2 3 4
| num1=100 num2=200 print(str(num1)+"大于"+str(num2) if num1>num2 else str(num1)+"小于"+str(num2))
|
占位符
1 2 3 4 5
| if num1>num2: pass else: print(111)
|
03codeStructure
https://jiajun.xyz/2020/10/12/python/01base/03codeStructure/