Help me fix the error

my second code shows me error : File “”, line 20
sum1 = sum1 += number for number in lst1
SyntaxError: invalid syntax

Hey there.

The error is telling you what’s wrong.

sum1 = sum1 += number for number in lst1 is not a valid statement in Python.

Thank you, but I wouldn’t ask if I would know how to fix it.
Can you please tell me how to fix it ?
What is wrong in it

How about treating python like a bunch of lego blocks that you can combine given that pegs and holes match up?

You’d pick a block, you’d investigate how that block needs to look… then pick a second block, make sure that’s well-formed as well, and then consider how those might fit, and now you have a bigger block made out of two blocks from which you can keep going.

You can’t obtain that code by combining valid smaller things.

Don’t start with the expectation that whatever it is should work, start with nothing and build on that.

Hey Ionatan, can you just tell me what is the problem and i can deduct conclusions from that ?
Thank you

I could faceroll my keyboard a bit:

etnsuhtnsaeohtnsa unthseoanthut nthsuontshu aonetheu nthstutnh nst

And then ask what the problem is, as if I expected it to mean something. My code doesn’t work, how to fix it?

The problem with facerolling as a means to produce code is that none of it is recognized by python. I would instead need to combine things that are known to the language, and only then can I hope to write something meaningful.

For example an assignment statement and an add expression:

blah = a + b

This is well formed code, because it follows the pattern of the assignment statement:


and adding is a valid expression:


so if I use the add expression in the assignment statement where an expression is allowed, then that would be okay.

You need to be able to point at the individual parts and argue for why each of them is okay. You can test the individual parts in isolation of each other if the whole thing doesn’t “work”, and if some individual part isn’t valid then you can go look for documentation for that thing to remind you of what it needs to look like.

Yeah, you let your cat walk across your keyboard and you kept whatever it was in your code. Don’t expect it to be meaningful though, it’s not something to be fixed just like how random characters aren’t something to be fixed, but redone.
And, because you already need to know what things you’ve written, you should already know enough to fix it too - I really don’t see how you can know what you’re writing and then not be able to spot the problem unless it was just made up in which case… don’t make stuff up, that’s not reasonable.