• if语句


    1,单 if 条件满足:
      if 条件:
      缩进 结果 

    name = "张浩"
    input_name=input("Input your name :")
    if input_name == name:
    print("Same name to me !")

    2,2条件满足其中一个条件:if  else

      if 条件:

      缩进 结果
      else:
      缩进 结果 

    name = "张浩"
    input_name=input("Input your name :")
    if input_name == name:
    print("Same name to me !")
    else:
    print("Different name to me !")

    3,多条件满足一个或都不符合 if elif elif elif

    • if 条件:

      缩进 结果

      elif 条件:

      缩进 结果

      elif 条件:

      缩进 结果

    name1 = "张浩"
    name2 = "Jack"
    name3 = "Brows"
    input_name=input("Input your name :")
    if input_name == name1:
    print("Same name to me !")
    elif input_name == name2:
    print("My bestfriend !")
    elif input_name == name3:
    print("My best friend's girlfriend !")

    4,多条件符合一个 if elif elif else

    • if 条件:

      缩进 结果

      elif 条件:

      缩进 结果

      elif 条件:

      缩进 结果

      else :

      缩进 结果

    name1 = "张浩"
    name2 = "Jack"
    name3 = "Brows"
    input_name=input("Input your name :")
    if input_name == name1:
    print("Same name to me !")
    elif input_name == name2:
    print("My bestfriend !")
    elif input_name == name3:
    print("My best friend's girlfriend !")
    else:
    print("I do not know you !")

    5,if 嵌套

    • if 条件:

      缩进 结果

      if 条件:

      缩进 结果

    your_score = int(input("Input your score :"))
    if your_score > 90:
    print("You are great !")
    if your_score == 100:
    print("You are No.1 !")
    else:
    print("Come on ,you can be No.1 next !")
    else:
    print("You need to study hard !")

     

      

      




  • 相关阅读:
    使用Maven Helper解决Maven依赖冲突
    bzoj 1037[ZJOI2008]生日聚会Party
    bzoj 1031[JSOI2007]字符加密
    bzoj 1029 [JSOI2007]建筑抢修
    bzoj 1025[SCOI2009]游戏
    bzoj 1027[JSOI2007]合金
    bzoj 1024[SCOI2009]生日快乐
    bzoj 1023[SHOI2008]cactus仙人掌图
    bzoj 1022 [SHOI2008]小约翰的游戏John
    bzoj 1021[SHOI2008]Debt 循环的债务
  • 原文地址:https://www.cnblogs.com/zzzhao/p/11334157.html
Copyright © 2020-2023  润新知