python 註冊登入 檔案操作

2022-04-02 06:22:21 字數 1851 閱讀 9071

name = input("

請註冊使用者:")

password = input("

請註冊密碼:")

with open(file="

user

", mode='

w', encoding='

utf-8

') as f:

f.write(

'{}\n{}

'.format(name, password))    # 將使用者、密碼寫入檔案

print("

恭喜%s,註冊成功!

" %name)

count =0

li =

while count < 3:  # 三次輸入機會

_name = input("

請輸入使用者:")

_password = input("

請輸入密碼:")

with open(file='

user

', mode='

r+', encoding='

utf-8

') as f:  # 讀取檔案

for line in

f:

if li[0].strip() == _name and li[1].strip() ==_password:

print("

登入成功!")

break

else

:

print("

請重新輸入!")

if count == 2:

print("

笨蛋,回家養豬去吧!!!!!")

count += 1

# 改良

name = input("

請註冊使用者:")

password = input("

請註冊密碼:")

with open(file="

{}".format(name), mode='

w', encoding='

utf-8

') as f:

f.write(

'{}\n{}

'.format(name, password))

print("

恭喜%s,註冊成功!

" %name)

count =0

#li =

while count < 3:

_name = input("

請輸入使用者:")

_password = input("

請輸入密碼:")

with open(file="

{}".format(name), mode='

r+', encoding='

utf-8

') as f:

#for line in f:

# li =f.readlines()

if li[0].strip() == _name and li[1].strip() ==_password:

print("

登入成功!")

break

else

:

print("

請重新輸入!")

if count == 2:

print("

笨蛋,回家養豬去吧!!!!!")

count += 1

過程1)使用者互動-註冊使用者、密碼

2)寫入檔案

3)while迴圈,3次機會

4)使用者互動-輸入使用者、密碼

5)讀檔案

6)str比較

python登入註冊實驗

from faker import faker fake faker locale yy cn 偽造中文資料 print fake.ssn class person def init self,yang yin,sec key self.y y yang yin self.sk sec key pe...

使用者註冊登入 和 資料寫入檔案的註冊登入

class user def init self,username,password self.username username self.password password class account def init self self.user list 目的是儲存使用者資訊 pass de...

python模擬註冊登入 python實現模擬登入

python實現模擬登入 2012 08 02 10 20 42 我來說兩句 當你要模擬登入乙個 時,首先要搞清楚 的登入處理細節 發了什麼樣的資料,給誰發等.我是通過httpfox來抓取http資料報來分析該 的登入流程。同時,我們還要分析抓到的post包的資料結構和header,要根據提交的資料...