728x90
반응형
filename = 'user.txt' # 사용자 정보를 저장할 파일명
Accounts = {} # 사용자 딕셔너리
def readUser(): # 파일을 읽어서 딕셔너리 만듬
f = open(filename, 'r')
for L in f:
tmp = L.split(':')
Accounts[tmp[0]] = tmp[1].strip()
f.close()
def writeUser(): # 딕셔너리를 파일로 저장
f = open(filename, 'w')
for k, v in Accounts.items():
f.write(k + ':' + v + '\n')
f.close()
readUser() # 처음 시작시 파일을 읽어 Accounts 딕셔너리를 만듬
while True:
msg = "-Type your ID\n"
msg += "-If you want to make a new ID, please type 'MakeAccount' : "
QuestionID = input(msg)
if QuestionID in Accounts.keys():
msg = 'Please type password for that ID : '
QuestionPW = input(msg)
if QuestionPW == Accounts[QuestionID]:
print('Log in Success.')
break
elif QuestionID == 'MakeAccount':
msg = 'Please type the name that you wnat to make for ID : '
QuestionMID = input(msg)
msg = 'Please type the password that you want to make. : '
QuestionMPW = input(msg)
# NewID = {QuestionMID : QuestionMPW}
print('Your ID is made. Congratulations!')
Accounts[QuestionMID] = QuestionMPW
writeUser() # Accounts 딕셔너리를 파일로 저장
elif QuestionID.upper() == 'Q':
break
applemac:AM
appleair:AA
applepro:AP
사용자 추가
728x90
반응형
'프로그램' 카테고리의 다른 글
[파이썬] 터틀(turtle) n각형들 가운데 정렬 그리기 (0) | 2023.05.01 |
---|---|
[파이썬] 문제 : 가위,바위,보 게임 (0) | 2023.05.01 |
[C언어] 4진수 변환 (0) | 2023.04.29 |
[파이썬] 문제 : 음악 플레이리스트 추가,삭제 (0) | 2023.04.28 |
[C언어] 2개의 실수 입력 받아서 두 실수 사이의 정수 합 표시 (0) | 2023.04.28 |
댓글