流程控制学习


1、单分支if
age_of_you = 25
if age_of_you >22:
  print(“time to find a bf.")
print("---------hahah")

2、双分支
age_of_you = 25
if age_of_you >22:
  print(“time to find a bf.")
else:
  print("还可以再。。。。")
print("---------hahah")

 

3、多分支
if 条件:
满足条件执行代码
elif 条件:
上面的条件不满足就走这个
elif 条件:
上面的条件不满足就走这个
elif 条件:
上面的条件不满足就走这个
else:
上面的所有条件不满足就走这段


4、while循环
while 条件:
  执行代码
#打印偶数
count = 0
while count <=100
  if count % 2 == 0#偶数
  print("loop",count)
count +=1


#第50次不打印,第60-80打印对应值的平方
count = 0
while count <=100
  if count == 50:
    pass #过的意思。。。

  elif count >= 60 and count <= 80:
    print(count*count)
  else:
    print(count)
    count += 1
    

猜你喜欢

转载自www.cnblogs.com/MrHB/p/9048531.html