#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목9/29 Lecture7 excercise 관련 질문2022-10-04 16:54
작성자

마지막 슬라이드에 있는 exercise 코드를 짜봤는데 실행은 되지만 문제점이 있습니다.

 

i=open("Exercise.txt","w")

ID=["myname\n", "1234"]

i.writelines(ID)

i.close()

k=open("./Exercise.txt","r")


while True:

    name=input("input your name: ")

    password=input("input your password: ")

    if k.readline()[:-1]==name and k.readline()==password:

        print("Success!")

        break

    else:

        print("Fail!")


print("The End")


무한루프로 ID 와 Password가 저장되어 있는 값과 일치 할때 까지 값을 입력받고 싶은데, 처음에 바로 아이디와 비밀번호를 맞췄을때는 정상적으로 success가 뜨는데 한번 틀려버리면 readline함수가 3번째줄, 4번째줄로 넘어가서 아무것도 치지 않아야 break가 걸립니다. read 함수중에서 사용자가 첫번째줄과 두번째 줄만 특정지어 읽을 수 있는 함수가 있는지 궁금합니다.

댓글
이전[re]step 07 if (if, elif) else flow chart 질문2022-10-06
다음[re]9/29 Lecture7 excercise 관련 질문2022-10-04