Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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
- 반복문
- Class
- raw data
- vscode
- 파이썬
- const
- predictive analysis
- pointer
- 백준
- C++
- Pre-processing
- 오블완
- string
- pass by reference
- function
- 함수
- Deep Learning
- OOP
- 배열
- 문자열
- 포인터
- Data Science
- baekjoon
- Python
- 티스토리챌린지
- Object Oriented Programming
- 알고리즘
- array
- programming
- assignment operator
Archives
- Today
- Total
Channi Studies
Terminating a Program (프로그램 종료) 본문
파이썬으로 기초적인 프로그램을 프로그래밍 하다 보면,
오류를 핸들링 해야 하는 경우가 많습니다.
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' 카테고리의 다른 글
| Tuple 튜플 (0) | 2025.01.26 |
|---|---|
| List 리스트 (0) | 2025.01.26 |
| Analyzing String | 문자열 함수들 (0) | 2025.01.12 |
| [baekjoon] 2563번 색종이 Python (0) | 2023.10.14 |
| [baekjoon] 10789번 세로읽기 Python (1) | 2023.10.14 |