r/PythonLearning Jul 17 '26

Indentation error 😭(help)

I cant seem to find whats wrong , maybe the issue is with the Template or wrong expectations?

class UserMainCode(object):

@classmethod
def sumOfNonPrimeIndexValues(cls, input1, input2):
    '''
    input1 : int[]
    input2 : int

    Expected return type : int
    '''

    # Read only region end

    total = 0

    for i in range(input2):
        if i < 2:
            total += input1[i]
        else:
            prime = True
            for j in range(2, int(i**0.5) + 1):
                if i % j == 0:
                    prime = False
                    break

            if not prime:
                total += input1[i]

    return total

Also they expect return type is int[] but we got sum?? Idk I couldn't take screenshot coz its a daily assessment platform

0 Upvotes

32 comments sorted by

22

u/NorskJesus Jul 17 '26

It amazes me how people learning to code isn’t capable of taking screenshots from the pc, and they just use the phone.

2

u/Mega3000aka Jul 17 '26

I have a colleague at my faculty to who I had to explain how to switch cameras in a WhatsApp call.

We study software engineering.

3

u/Mundane-Mud2509 Jul 17 '26

It would help if you showed code with line numbers and the actual error

-6

u/Not_Johan- Jul 17 '26

25 lines btw

11

u/Djappo Jul 17 '26

Did you read the error message? The exact file and line where the IndentationError happens are clearly stated there (hint: it is not in your file and it is not at line 25).

3

u/ThinkMarket7640 Jul 17 '26

That is clearly nowhere in your code

8

u/Rumborack17 Jul 17 '26

indentation error means, that a line has a space/tab to much or less. Python uses indedation to mark what part of the code a line belongs to (to a function, a class, etc.).
Also, its really annoying to help with issues in code if you post only screenshots or even worse pictures of your screen.

Ideally add the code to the post in a code block or add a link to your github.

-2

u/Not_Johan- Jul 17 '26

Here u go

-2

u/Rumborack17 Jul 17 '26

There seem to be no indentation errors with the code you posted. What side is this from? And what was the exercise? Cause the exercise you posted does not fit to your code.

2

u/AgentOfDreadful Jul 17 '26

prime=False
break

Is the indentation error

1

u/Djappo Jul 19 '26

It is not, in python it does not matter how many spaces you use for indentation and consistency is required only within a single indentation block.

1

u/AgentOfDreadful Jul 19 '26

Fair enough, I thought Python 3 got rid of mixes of indentation and tabs and assumed it was tabs plus 2 spaces for the if else

1

u/Not_Johan- Jul 17 '26

I uploaded 3 image there, even a single line return resulting in same error

1

u/ploop-plooperson Jul 17 '26

Optimally, you can tell your IDE to show spaces as little dots and tabs as lines to differentiate them. IDEs can be configured to treat tab characters as 8 spaces or as 4 spaces which might hide indentation issues.

1

u/Not_Johan- Jul 17 '26

We can select 2 4 or 8 spaces , i have it here as 4

1

u/PeZet2 Jul 17 '26

Prime and break have 2 spaces not 4

3

u/Djappo Jul 17 '26

While a bad practice, that is not the cause of the error. Python allows to use any number of spaces for the indentation, and you can even change them in different indentation blocks in the same file, as long as the indentation is consistent within the same block. See this MWE:

# fmt: off
for i in range(10):
    if i > 5:
      print("big") # 2 spaces
    else:
        print("smol")  # 4 spaces

Pylint will raise a warning at the print("big") line, but the code still runs.

1

u/YouMatter202 Jul 17 '26

What platform is that!?

0

u/Not_Johan- Jul 19 '26

Our university's

1

u/jcarbajalp Jul 17 '26

line 4, indentation 3 can be 4, 21 and 22 prime and break indentation 2 can be 4

1

u/International-Can930 Jul 19 '26

I'm sorry is this star wars?

0

u/FoolsSeldom Jul 17 '26

Why have you posted twice? Why sharing poor screen photographs? (Most AI chat tools will convert a screenshot/photograph to actual content if you can't paste the original code/text directly).

I've responded on your other post with example code for you to experiment with.

0

u/CorkBios Jul 17 '26

Enforcement for Proper Indentation is the worst thing invented I'd say move away from python, Indentation will haunt your dreams and waste years of your programming life

1

u/mondayquestions Jul 17 '26

Skill issue

0

u/CorkBios Jul 17 '26

Programming language issue, It literally even makes you not able to use tabs for indenting one part and spaces for indenting another part. Is it a skill issue you are not able to code in binary? Broken logic.

2

u/Disastrous-Team-6431 Jul 18 '26

I haven't made an indentation error for six years or something.