-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_handling.py
More file actions
46 lines (30 loc) · 893 Bytes
/
Copy patherror_handling.py
File metadata and controls
46 lines (30 loc) · 893 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
#### try and except
###error handing
import sys
def divide42(value):
try:
return 42/value
except ZeroDivisionError:
print ('zero is not allowed')
except TypeError:
print ('input function needs to be converted in integer')
except ValueError:
print ('enter interger')
print (divide42(0))
print (divide42(5))
print (divide42(10))
####commenting out below line to test except typerror
#num1 = int(input('enter number: '))
num1 = input('enter number: ')
print (divide42(num1))
print ('enter the number of cats')
num = input()
try:
if int(num)>=4:
print ('you have more than 4 cats')
elif int(num)<0:
print ('you have entered negative value...exiting the program')
else:
print ('you have less than 4 cats')
except:
print ('you have not entered a number...exiting the program')