list1=[‘a’,‘b’,‘c’]
list2=list1.copy()
print(list2)
纯计算无IO(输入输出)的死循环会导致致命的效率问题(卡死)
比如
while true:
1+1
需求:超出3次输错则退出登录:
tag = 1
while tag<=3:
inp_name = input(‘请输入账号:’)
inp_pwd = input(‘请输入密码:’)
if inp_name != ‘3’ or inp_pwd != ‘4’:
if tag == 3:
print(“输错超出次数”)
else:
print(‘账号密码错误!’)
tag=tag+1
else:
print(‘登录成功’)
break
新增需求:超出3次输错则等待10s后继续输入
import time
tag = 1
while tag<=3:
inp_name = input(‘请输入账号:’)
inp_pwd = input(‘请输入密码:’)
if inp_name != ‘3’ or inp_pwd != ‘4’:
if tag == 3:
print(“输错超出次数,请10s后再尝试”)
time.sleep(10)
tag=1
else:
print(‘账号密码错误!’)
tag=tag+1
else:
print(‘登录成功’)
break