lundi 11 janvier 2021

simplifying- if statements

I have this code right here but I don't understand how to simplify the code, does anyone have an idea on how to simplify codes like these

if ball.ycor() > 340:
    ball.sety(340)
    ball.ycoor *= -1

if ball.ycor() < -340:
    ball.sety(-340)
    ball.ycoor *= -1

if ball.xcor() > 490:
    ball.goto(0,0)
    ball.xcoor *= -1
    scoreboard_a += 1
    score.clear()
    score.write("{}           {}".format(scoreboard_a,scoreboard_b), font=("Arial",104,"normal"))

if ball.xcor() < -490:
    ball.goto(0,0)
    ball.xcoor *= -1
    scoreboard_b += 1
    score.clear()
    score.write("{}           {}".format(scoreboard_a,scoreboard_b), font=("Arial",104,"normal"))


if (ball.xcor() > 440 and ball.xcor() < 450) and ball.ycor() < block_b.ycor() + 40 and ball.ycor() > block_b.ycor() - 40:
    ball.setx(440)
    ball.xcoor *= -1
   

if (ball.xcor() < -440 and ball.xcor() > -450) and ball.ycor() > block_a.ycor() - 40 and ball.ycor() < block_a.ycor() + 40:
    ball.setx(-440)
    ball.xcoor *= -1

Aucun commentaire:

Enregistrer un commentaire