Exception
- handle errors in python program
- exit code 0 means program terminated successfully.
try:
age = int(input('Age: '))
print(age)
except ValueError:
print('Invalid value')
try:
age = int(input('Age: '))
income = 20000
risk = income / age
print(age)
except ZeroDivisionError:
print('Age can not be 0.')
except ValueError:
print('Invalid value')
Comments
- should not explain what a code does
- use comments to
- explain why and how
- explain assunptions
- remind sth. to be done