[Solved] Python – keeps reporting a syntax erro on the ‘elif’ statement


I agree that you should consider changing your single line comments to use the pound symbol. I ran your code and once I indented the multiline comments, the syntax error disappeared. As the other answers mentioned, following an if statement, the compiler expects either once-more indented code or an elif statement or new code at the same indentation-level as your if.

def draw(canvas):
    global score1, score2, pad1_pos, pad2_pos, ball_vel, RIGHT, c
        # update ball
    '''
    reflections on the left wall
    '''
    if (ball_pos[0] == BALL_RADIUS + PAD_WIDTH) and (ball_pos in [range(pad1_pos, pad1_pos + PAD_HEIGHT)]):
        print ball_pos
        ball_vel[0] = - ball_vel[1]
        ball_vel[1] = ball_vel[1]
        c += 10

    elif (ball_pos[0] == BALL_RADIUS + PAD_WIDTH) and (ball_pos in [range(pad1_pos, pad1_pos + PAD_HEIGHT)]):
        print ball_pos
        ball_vel[0] = - ball_vel[1]
        ball_vel[1] = ball_vel[1]
        c += 10

    elif ball_pos[0] == (WIDTH - 1) - BALL_RADIUS - PAD_WIDTH and (ball_pos in range(pad2_pos, pad2_pos + PAD_HEIGHT)):
        '''remember how Python counts the values starting from 0'''
        '''the first pixel of a 600p wall is 0 and the last one is 599'''
        ball_vel[0] = - ball_vel[1]
        ball_vel[1] = ball_vel [1]
        c += 10

        '''scoring of paddle2'''
    elif ball_pos[0] == (WIDTH - 1) - BALL_RADIUS - PAD_WIDTH and not (ball_pos in range(pad2_pos, pad2_pos + PAD_HEIGHT)):
        score1 += 1
        spawn_ball()
        RIGHT = True

        '''reflections on the upper wall'''
    elif ball_pos[1] == BALL_RADIUS:
        ball_vel[0] = ball_vel[0]
        ball_vel[1] = - ball_vel[1]

        '''reflections on the bottom wall'''
    elif ball_pos[1] == (HEIGHT - 1) - BALL_RADIUS:
        ball_vel[0] = ball_vel[0]
        ball_vel[1] = - ball_vel[1]

0

solved Python – keeps reporting a syntax erro on the ‘elif’ statement