ํ์ด์ฌ์ผ๋ก ๊ธฐ์ด์ ์ธ ํ๋ก๊ทธ๋จ์ ํ๋ก๊ทธ๋๋ฐ ํ๋ค ๋ณด๋ฉด,
์ค๋ฅ๋ฅผ ํธ๋ค๋ง ํด์ผ ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค.
When user enters invalid input, it is common to abort the program.
๊ทธ๋ ๊ฒ ํ๊ธฐ ์ํด์๋, sys standard library module์ ์ ์๋ exit ํจ์๋ฅผ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
from sys import exit
if not (userResponse == "n" or userResponse == "y"):
exit("Error: you must enter either n or y.")
exit(errorMessage) ํ์์ผ๋ก ํ๋ก๊ทธ๋จ terminate ์์ ์ถ๋ ฅ๋ ์๋ฌ ๋ฉ์์ง๋ฅผ ์ธ์๋ก ๋ฃ์ผ๋ฉด ๋ฉ๋๋ค.
'python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Analyzing String | ๋ฌธ์์ด ํจ์๋ค (0) | 2025.01.12 |
---|---|
[baekjoon] 2563๋ฒ ์์ข ์ด Python (0) | 2023.10.14 |
[baekjoon] 10789๋ฒ ์ธ๋ก์ฝ๊ธฐ Python (1) | 2023.10.14 |
[programmers] ๋ฌธ์์ด ์ฌ๋ฌ๋ฒ ๋ค์ง๊ธฐ (python) (8) | 2023.10.11 |
[python] tkinter miles km converter / tkinter ๋ง์ผ ํฌ๋ก๋ฏธํฐ ๋ณํ๊ธฐ (3) | 2023.10.10 |