먼저 생각하기 · 기초
다음 모습 예상하기: 두 동작 사이에 다른 일이 끼어드는 틈을 찾아요
생활 장면은 이래요. 직원이 표를 확인한 순간과 읽는 순간 사이에 새 표가 바뀌는 장면을 그대로 다시 만들어 봐요. 다음 모습을 먼저 예상하고 짧은 Python 코드, 즉 컴퓨터가 따라 할 글로 확인합니다.
아래 글을 아직 컴퓨터가 따라 하게 하지 말고, 마지막에 보일 모습과 그렇게 생각한 까닭을 먼저 적으세요. from pathlib import Path from tempfile import TemporaryDirectory with TemporaryDirectory() as room: note = Path(room) / "today.txt" note.write_text("A", encoding="utf-8") seen = note.read_text(encoding="utf-8") note.write_text("B", encoding="utf-8") print(seen, note.read_text(encoding="utf-8"))
- 첫 글: from pathlib import Path from tempfile import TemporaryDirectory with TemporaryDirectory() as room: note = Path(room) / "today.txt" note.write_text("A", encoding="utf-8") seen = note.read_text(encoding="utf-8") note.write_text("B", encoding="utf-8") print(seen, note.read_text(encoding="utf-8"))
- 공개 풀이를 보기 전에 예상과 그렇게 생각한 까닭을 먼저 적습니다.
- 실제 이름·연락처·계정 정보 대신 수업용 글자와 작은 수만 사용합니다.
연습과 같은 문제를 다시 풀어 보는 시간이에요. 힌트 없이 먼저 생각해 보세요. 지금 적은 답은 바로 합격으로 기록되지 않아요.
