The issue is with this line:
motion.x = min(motion.x + moveSpeed,maxSpeed)
Notice that its indent level matches that of the previous
if block. That effectively ends the
if block so the following
elif no longer makes sense.
I'm not sure what your intention is there. If that
motion.x line is intended to be part of the
if logic, indent it to indicate that. If it's not part of the
if logic, then it shouldn't be there at all and needs to be moved to wherever is appropriate.