if 判断语句

if 条件:
if语句块
当条件成立的时候会执行if语句块, 如果条件不成立. 不执行语句块的内容

例:

money = int(input("请输入你兜里的钱:")) # 300
if money > 500:
    print("吃烧烤")
    print("喝啤酒")
    print("找好朋友聊聊天")
else:  # 否则. 条件不成立
    print("吃泡面")
    print("盖浇饭")
    print("老干妈+馒头")


if money > 500:
    print("吃烧烤")
    print("喝啤酒")
    print("找好朋友聊聊天")
elif money > 400:  #  否则. 如果xxxx
    print("火锅")
    print("酱牛肉")
    print("锅包肉")
# elif money >10:
#     print("呵呵")
elif money > 300:
    print("路边摊")
    print("大宝剑")
elif money > 200:
    print("麻辣香锅")
    print("盖浇饭")
elif money > 100:
    print("烤冷面")
else: # 小于100
    print("饿着")

# if...elif...else 有一个成立了.其他的都不走了
print("没钱了")

# 90 -> 优秀(A)
# 80 -> 良好(B)
# 70 -> 中等(C)
# 60 -> 及格
# 60 以下 不及格
# 优秀, 良好, 中等, 及格, 不及格

score = int(input("请输入你的分数:"))
if score >= 90:
    print("优秀")
elif score >= 80:
    print("良好")
elif score >= 70:
    print("中等")
elif score >= 60:
    print("及格")
else:
    print("不及格")

if 嵌套
print("咣咣咣")
gender = input("请输入你的性别:")
if gender == "男": # = 赋值     == 判断
    print("去隔壁. alex等着你")
else: # 不是男
    ask = input("请问是包租婆么?")
    if ask == "是":
        print("去隔壁, alex等着你, wusir也在!")
    else: # 不是包租婆
        height = int(input("请问你多高了"))
        if height > 200:
            print("太可怕了. 去隔壁, 去隔壁")
        else:
            print("西瓜又大又甜!")
# 嵌套的层数不要太多. 一般不超过3-5层

  

猜你喜欢

转载自www.cnblogs.com/YangWenYu-6/p/10022538.html