+ 1
Error in my code.
It's my task: https://www.sololearn.com/coach/1060?ref=app It's my code: text = input() text = list(text) my_dict = {} x = 1 for i in range(len(text)): if text[i] not in my_dict: my_dict[text[i]] = x elif text[i] in my_dict: my_dict[text[i]] = x+1 print(my_dict) What's my error?
2 odpowiedzi
+ 1
text = input()
text = list(text)
my_dict = {}
x = 1
for i in range(len(text)):
if text[i] not in my_dict:
my_dict[text[i]] = x
elif text[i] in my_dict:
my_dict[text[i]] = x+1
print(my_dict)
+ 2
i’m guessing your error is that you are letter count maxes out at 2.
in your elif statement you have dict = x+1. in this case x is always equal to 1, so x+ 1 will equal 2. in any other case, you would need a x += 1 or x = x+1 for the value of x to increase.
for your answer though, i think all you need to do is replace x+1 with my_dict[text[i]] + 1 so it will add 1 to the existing count value.