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 !")

 

 

  

  

 




posted on 2019-08-11 10:37  一抹天空  阅读(135)  评论(0编辑  收藏  举报

导航