- if语句
if 条件语句: 代码
- 1两种情况处理
age = input("请输入年龄:") age = int(age) if age >= 18: print("仗剑走天涯") else: print("回家吃奶")
- 2多种情况判断处理
# 进行不同情况的判断处理 # >100 <0 # 90-100 A # 80-89 B # 60-79 C # 60以下 D socre = input("请输入成绩:") socre = int(socre) # 转换类型 if socre > 100 or socre < 0: print("不合法的成绩") elif socre >= 90 and socre <= 100: print("A") elif socre >= 80 and socre <= 89: print("B") elif socre >= 60 and socre <= 79: print("C") else: print("D")
- 3if嵌套
# 1. 机场入口安检 # 2. 登机前安检 k = input("是否携带违禁物品(0,没有;1,携带):") if int(k) == 1: print("不好意思,您需要派出所一日游") else: print("可以进站") name = input("请出示您的身份证:") if name == "小明&#