'str' object is not callable

What am I doing wrong here?

ABC = "abcdefghijklmnopqrstuvwxyz"

new_message = "dfc aruw fsti gr vjtwhr wznj? vmph otis! cbx swv jipreneo uhllj kpi rahjib eg fjdkwkedhmp!"
keyword = "friends"

keyword_values = ""
message_value = ""

decoded_message = ""

no_spaces = new_message.replace(" ", "")
no_quest = no_spaces.replace("?", "")
no_exc = no_quest.replace("!", "")

for i in range(len(no_exc)):
    keyword_index = i % len(keyword)
    keyword_value = ABC.find(keyword[keyword_index])
    keyword_values += str(keyword_value)
print(keyword_values)

for letter in no_exc:
    message_value += str(ABC.find(letter))
print(message_value)

for i in range(len(no_exc)):
    decoded_message += (int(message_value(i))) - (int(keyword_values(i))) % 26

print(decoded_message)

Here’s my error message:

     25 for i in range(len(no_exc)):
---> 26     decoded_message += str((int(message_value(i))) - (int(keyword_values(i))) % 26)
     27 
     28 print(decoded_message)

TypeError: 'str' object is not callable

message_value contains a string, strings aren’t callable.

by doing message_value(), you attempt a function call. Not sure what you are attempting, but to access a string by index, use square brackets ([])

if you need more help, share the exercise url so i can read the instructions, trying to understand what the requirements are.

2 Likes