#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http 제목[re]9/29 Lecture7 excercise 관련 질문2022-10-04 16:59작성자박상근여러 방법으로 해결할 수 있겠지만, 간단한 두 가지 방법을 소개해드립니다.1. 파일을 While문 안에서 열기i=open("Exercise.txt","w")ID=["myname\n", "1234"]i.writelines(ID)i.close()while True: with open("./Exercise.txt","r") as k: 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")2. seek(n) 함수 사용하기. https://blog.naver.com/jkg57/222120795434 참고. 수업시간에 배운 내용은 아니지만 이런 방법도 있습니다.i=open("Exercise.txt","w")ID=["myname\n", "1234"]i.writelines(ID)i.close()k=open("./Exercise.txt","r")while True: k.seek(0). # read를 하더라도 처음부터 읽도록 다시 파일의 처음위치(0)으로 돌아가기. 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") 목록수정삭제답변글쓰기 댓글 [0] 댓글작성자(*)비밀번호(*)내용(*) 댓글 등록 더보기이전9/29 Lecture7 excercise 관련 질문박상근 교수님 웹파 수강생2022-10-04다음steo_o7_conditionalstatement 짝수/홀수 판정 프로그램 개발하기isd2022-09-30 Powered by MangBoard | 워드프레스 쇼핑몰 망보드