Notice
Recent Posts
Recent Comments
Link
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Tags
more
Archives
Today
Total
관리 메뉴

PythonHolic

[python] id 와 pw 를 확인하는 문제 본문

파이썬 과제 도와주기 일지

[python] id 와 pw 를 확인하는 문제

devpy 2020. 6. 25. 14:59

Question. 중첩 if문을 사용하여 아이디와 패스워드를 검사하는 프로그램을 작성하시오. 단, 아이디가 틀리면 계속 다시 시도, 패스워드가 5번 틀리면 루프를 빠져나오도록 하여라

 

id_lst = ['asdf','fdsa','qwer','rewq']
pw_lst = ['asdf1234','fdsa1234','qwer1234','rewq1234']
 
count = 4
while True:
    inpt = input("아이디를 입력하시오 : ")
    if inpt in id_lst:
        index = id_lst.index(inpt)
        while count>=0:
            inpt2 = input("비밀번호를 입력하시오 : ")
            if inpt2 == pw_lst[index]:
                print(pw_lst[index])
                print("로그인 성공")
                break
            else:
                print("기회는 {}번 남았습니다".format(count))
                count-=1
        if count==0:
            break
        break
 
 
Comments