Light Mode
Dark Mode
TypeError: 'bool' object is not subscriptable

coding : utf-8

def sum_numbers(text: str) -> int:

test1=""
figure="0123456789"
summ=0
space=False
number=False

for i in range(len(text)) : # checking caracters
    for j in range(len(figure)) : # checking figures
            alpha=text[i]
          _ **cool=figure[j]**_
            if alpha==cool :
                number=True

                if (number and figure) or (number and figure==False): #recontruction of the number
                    test1=test1+alpha
                    figure=True

                elif(number==False and figure) or (i==len(text)-1): #conversion and addition
                    summ=summ+int(test1)
                    figure=False
                    number=False

return summ

print("Example:") print(sum_numbers("hi. I'm 40 and he's 200. Ok?"))

""" We have a "TypeError: 'bool' object is not subscriptable" when we compile the program. When does the "cool" String variable become boolean??? How to fixed this error? """

Attachment
Created: March 16, 2023, 10:39 p.m.
Updated: March 17, 2023, 2:44 p.m.
0
4
User avatar
jeanroland.business