STEP 16: To calculate where our ball should go, we need a new y-coordinate. bally (our current position) + rise (how far we move up) is the answer! But using rise will put the ball in the net every time! We need to use what the rise would be with the slope the user guessed. To get our new rise, we'll use slopeguess = rise/run and solve for rise!

  • In LOGIC, click and drag out Multiplication.
  • Change my_var to newrise, and replace 2 * 3 with slopeguess * run!

stage.set_axis(100) stage.create_grid_overlay(10, "grey") stage.set_background("soccerfield") ballx = -80 bally = random.randint(-100,100) # sprite = codesters.Sprite("image", x, y) ball = codesters.Sprite("soccerball", ballx, bally) netx = 90 nety = random.randint(-100,100) # sprite = codesters.Sprite("image", x, y) net = codesters.Sprite("soccernet", netx, nety) net.flip_right_left() #sprite = codesters.Line(x-start, y-start, x-end, y-end, "color") line = codesters.Line(ballx, bally, netx, nety, "blue") slopeguess = float(line.ask("What is the slope of this line?")) rise = nety - bally run = netx - ballx slope = rise / run # sprite = codesters.Text("text", x, y) sprite = codesters.Text(slope, 0, 30)