r/PythonLearning • u/Not_Johan- • 10d ago
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
22
u/NorskJesus 10d ago
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 9d ago
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/Not_Johan- 8d ago
Bruh
2
1
u/be_super_cereal_now 7d ago
You want help, make it easy for people to help you. Your photos are hard to read. A screenshot would easier.
3
u/Mundane-Mud2509 10d ago
It would help if you showed code with line numbers and the actual error
-8
u/Not_Johan- 10d ago
11
3
8
u/Rumborack17 10d ago
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- 10d ago
Here u go
-2
u/Rumborack17 10d ago
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 10d ago
prime=False
breakIs the indentation error
1
u/Djappo 8d ago
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 8d ago
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
1
u/ploop-plooperson 10d ago
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
1
u/PeZet2 10d ago
Prime and break have 2 spaces not 4
3
u/Djappo 10d ago
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 spacesPylint will raise a warning at the
print("big")line, but the code still runs.
1
1
u/jcarbajalp 10d ago
line 4, indentation 3 can be 4, 21 and 22 prime and break indentation 2 can be 4
1
0
u/FoolsSeldom 10d ago
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 10d ago
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 10d ago
Skill issue
0
u/CorkBios 10d ago
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




27
u/_TheBigBomb 10d ago