-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathL8Problem2.py
73 lines (63 loc) · 1.7 KB
/
L8Problem2.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# def FancyDivide(numbers,index):
# try:
# denom = numbers[index]
# for i in range(len(numbers)):
# numbers[i] /= denom
# except IndexError, e:
# print "-1"
# else:
# print "1"
# finally:
# print "0"
def FancyDivide(numbers, index):
try:
denom = numbers[index]
for i in range(len(numbers)):
numbers[i] /= denom
except IndexError, e:
FancyDivide(numbers, len(numbers) - 1)
except ZeroDivisionError, e:
print "-2"
else:
print "1"
finally:
print "0"
# def FancyDivide(numbers, index):
# try:
# try:
# denom = numbers[index]
# for i in range(len(numbers)):
# numbers[i] /= denom
# except IndexError, e:
# FancyDivide(numbers, len(numbers) - 1)
# else:
# print "1"
# finally:
# print "0"
# except ZeroDivisionError, e:
# print "-2"
# def FancyDivide(list_of_numbers, index):
# try:
# try:
# raise Exception("0")
# finally:
# denom = list_of_numbers[index]
# for i in range(len(list_of_numbers)):
# list_of_numbers[i] /= denom
# except Exception, e:
# print e
# def FancyDivide(list_of_numbers, index):
# try:
# try:
# denom = list_of_numbers[index]
# for i in range(len(list_of_numbers)):
# list_of_numbers[i] /= denom
# finally:
# raise Exception("0")
# except Exception, e:
# print e
FancyDivide([0, 2, 4], 1)
print('-----')
FancyDivide([0, 2, 4], 4)
print('-----')
FancyDivide([0, 2, 4], 0)