標籤:while lex 退出 readline nbsp error you 第一周 int
python課時第一周:_username = ‘alex‘
_password = ‘abc123‘
username = input("username:")
password = input("paaword:")
if username ==_username and password == _password:
print("welcome to us system")
else:
print("error")判斷密碼與帳號是否正確。count =0;
old_boy = 56
while count<3:
guess_age = int(input("guess_age:"))
count = count +1
if guess_age == old_boy:
print("yes,you winner")
break
elif guess_age < old_boy:
print("smaller..")
else:
print("bigger..")
else:
print("you have guess too many times, fuck off...")一個判斷大小的小遊戲,判斷三次,這是部落格登陸的一個前驅模式。
#Author lipengfei
#coding --utf-8---
lock_file = open(‘file_lock.txt‘,‘r+‘)
user_file = open(‘username_file.txt‘,‘r+‘)
count = 0
cmd = input(‘‘‘
1:登陸系統
2.推出系統
......
請輸入你的操作:‘‘‘)
if cmd.isdigit() and int(cmd) == 2:
exit()
elif cmd.isdigit() and int(cmd) == 1:
while count<3 :
username = input(‘請輸入您的使用者名稱:‘)
count = count +1
for i in lock_file.readlines():
i = i.split()
if username in i[0] :
print(‘對不起%s鎖定‘%username)
exit()
match = False
for j in user_file.readlines() :
user,password = j.strip(‘\n‘).split()
if username ==user:
passwd = input(‘請輸入密碼:‘)
if password == passwd :
print(‘使用者名稱和密碼正確‘)
match = True
elif passwd != password :
for i in range(0,2) :
passwd = input(‘密碼錯誤,請重新輸入....‘)
if password == passwd :
print(‘使用者名稱和密碼正確‘)
match = True
break
if username != user :
print(‘您輸入的使用者名稱錯誤‘)
exit()
elif match == False :
print(‘密碼和使用者名稱不匹配次數超過三次,鎖定‘)
lock_file.write(‘%s \n‘%username)
lock_file.close()
user_file.close()
exit()
elif match == True :
print(‘登陸成功‘)
break
else:
print("無效選擇,程式退出")
exit()#輸錯三次之後進行鎖定
歡迎大家測試
python第一期