I am trying to execute following code :
Given a getStr() function, write the necessary sequence of operations to transform the string (containing three literals) in such a way that every literal is tripled? respectively.
def getstr(s) :
result = 0
for i in s :
result = result + int(s[i] * 3)
#strlen = len(s)
return result
print(getstr("abc"))
And it gives me a following error.
TypeError Traceback (most recent call last)
<ipython-input-72-87f4e23e4363> in <module>
6 return result
7
----> 8 print(getstr("abc"))
<ipython-input-72-87f4e23e4363> in getstr(s)
2 result = 0
3 for i in s :
----> 4 result = result + int(s[i] * 3)
5 #strlen = len(s)
6 return result
TypeError: string indices must be integers
What is the issue ?