티스토리 뷰

Test/Python(20220101~)

나만의 예외, raise

kiostory 2022. 9. 18. 12:19
#BMI Example

height = float(input("Height: "))
weight = int(input("Weight: "))

if height > 3:
    raise ValueError("Human Height should not be over 3 meters.")

bmi = weight / height ** 2
print(bmi)

 

 

----------------------------------------


Height: 43
Weight: 65
Traceback (most recent call last):
  File "C:\Users\kiost\PycharmProjects\pythonProject\Days30_HandlingErrorsandExceptions\main.py", line 55, in <module>
    raise ValueError("Human Height should not be over 3 meters.")
ValueError: Human Height should not be over 3 meters.

Process finished with exit code 1

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/08   »
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
글 보관함