-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask 0 q5
34 lines (29 loc) · 820 Bytes
/
Task 0 q5
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
#assigning values to letters
def strength(a):
if a=='A':
return 1
elif a=='B':
return 2
else :
return 3
#simple adding letter values to a variable and multiplying with numbers immediately followed by
def sum(s):
k=0
for i in range(len(s)):
if s[i-1] in ['A','B','C']:
if i > len(s)-1 :
k+=strength(s[i-1])
elif s[i] in ['2','3','4','5','6','7','8','9']:
k+=strength(s[i-1]) * int(s[i])
i+=1
else:
k+=strength(s[i-1])
return k
s=input()
#since () has zero value replacing ( to) so that it can be removed from string input
a=s.replace ( "(" , ')' )
b=a.split(")")
total_strength=0
for i in range (len(b)):
total_strength+=sum(b[i-1])
print(total_strength)