Reputation: 913
I'm a beginner in python.
I code to receive a string and find it's most occurring character
userInput=input()
my_input=list(userInput)
count= {}
for num in my_input:
count[num] = count.get(num,0)+1
m=max(count)
print(m)
when i executed i receive this error
File "third.py", line 8
m=max(count)
^
IndentationError: unindent does not match any outer indentation level
Upvotes: 1
Views: 3546
Reputation: 535
userInput=input()
my_input=list(userInput)
count= {}
for num in my_input:
count[num] = count.get(num,0)+1
^ this is at the 5th blank space indent
m=max(count)
^ this is at the 4th space indent (the correct one)
print(m)
so whats happening is its throwing it off with your uneven spacing. Try to stick to 4 spaces or just 1-tab(but make sure your IDE can convert it to spaces).
Upvotes: 0
Reputation: 2337
Typically, these errors are in the line before what it shown in the error. And I can easily see that your count[num]
is one space too far to the right. I think that indentation in Python is typically 4 spaces from the left margin.
Depending on your text editor, you could also fix it by deleting the spaces before the lines in the for
loop, i.e.
for num in my_inputs:
count[num] = count.get(num, 0)+1
m=max(count)
and then pressing the tab
key to format them.
for num in my_inputs:
count[num] = count.get(num, 0)+1
m=max(count)
Upvotes: 1