if else
语法:
if :
分支1
elif :
分支2
else:
分支3
eg:
1 age = int(input("inpute you age"))
2 if age >= 18:
3 print("you are a person")
4 elif 6 <= age:
5 print("you are a child")
6 else:
7 print("you are a baby")
输出
12 you are a person
7 you are a child
4 you are a baby
while循环
语法1:while后判断条件成立时执行分支1,条件不成立则跳出循环继续向下执行。
while :
分支1
语法2:while没有被break且判断条件不为真会执行分支2。
while :
分支1
else:
分支2
count = 0
while count < 3:
age = int(input("inpute you age"))
if age > 56:
print("you inpute bigger")
elif age < 56:
print("you inpute smaller")
else:
print("you got it")
break
count += 1
else:
print("you trying more time")
for循环
语法1:循环体正常执行时,执行分支1;当循环体正常执行完且没有break则执行分支2.
for 循环体:
分支1
else:
分支2
1 for i in range (3):
2 age = int(input("inpute you age"))
3 if age > 56:
4 print("you inpute bigger")
5 elif age < 56:
6 print("you inpute smaller")
7 else:
8 print("you got it")
9 break
10 else:
11 print("you trying more time")
continue break
语法:continue无条件结束本次循环,跳到下一次循环;break跳出整个循环
1 for i in range(10):
2 if i <= 5:
3 print(i)
4 elif i < 8:
5 continue
6 elif i == 8:
7 print("i = 8,break")
8 break
9 else:
10 print("this isn't print")
标签:python,age,else,break,inpute,print,分支
来源: https://www.cnblogs.com/flags-blog/p/11756157.html