why doesn’t += work in a while true loop python?

This is because variable += val is shorthand for
variable = variable + val
As this is an assignment expression, and doesn’t return anything, that’s why this is considered to be a syntax error.

Note 1: This has nothing to do with while loop, it’s universally unaccepted

Note 2: Python doesn’t support ++ / — operators as of now

So, do this instead:

taken = 1
first = int(input("   "))
while taken <= 6:
        taken+=1
        print(f"1\n{taken}")

Leave a Comment