判断与循环

判断

if 判断

if 条件1:

    代码1

elif 条件2:

    代码2

else 条件3:

    代码3

score = input("请输入你的成绩:")
score = int(score)
if score > 90:
print("真棒,成绩优秀")
elif score > 80:
print("保持,成绩良好")
elif score > 70:
print("努力,小心掉队")
else:
print("回家吧")
* if循环里面也可以嵌套循环

 循环

 while循环:

while条件:

    代码1

    代码1

count = 0
username = "张三"
psd = "123"
while count < 3:
inp_username = input("请输入你的账号:")
inp_psd = input("请输入你的密码:")
if inp_username ==username and inp_psd == psd:
print("登录成功")
break
else:
print("登录失败,请重新输入")
count +=1

 死循环:

while True:
print("我会一直循环下去")

 *纯重复无意义的IO死循环会导致致命的效率问题

while True:
input("请输入你的名字")

 有条件的死循环

for循环:

主要是遍历取值,字符串也适用于for 循环

l = [22,33,77,42,24]
for i in l:
print(i)

 

 

 

posted on 2020-03-20 17:42  fdsimin  阅读(154)  评论(0编辑  收藏  举报