zoukankan      html  css  js  c++  java
  • 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 !")

     

      

      




  • 相关阅读:
    Easy Climb UVA
    POJ 2823 滑动窗口 单调队列模板
    Feel Good
    Problem J. Joseph’s Problem 约瑟夫问题--余数之和
    hdu 1029 Ignatius and the Princess IV
    poj 1027 Ignatius and the Princess II全排列
    Problem C Updating a Dictionary
    hdu 1412 {A}+{B}
    hdu 4006 The kth great number
    实现:职工管理系统
  • 原文地址:https://www.cnblogs.com/zzzhao/p/11334157.html
Copyright © 2011-2022 走看看