python第一期

來源:互聯網
上載者:User

標籤: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第一期

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.