-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathres3-1.py
27 lines (27 loc) · 888 Bytes
/
res3-1.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
sum = 0
with open('input3.txt', 'r') as f:
for n in f:
index = 0
while index < len(n) - 6:
try:
if n[index:index+4] == "mul(":
index += 4
a=''
while n[index].isdigit():
a += n[index]
index += 1
if n[index] == ',':
index += 1
b=''
while n[index].isdigit():
b += n[index]
index += 1
if n[index] == ')':
index += 1
sum += int(a)*int(b)
else:
index += 1
except Exception as e:
print(e)
break
print(sum)