PASO 16: Para calcular hacia dónde debe ir nuestra pelota, necesitamos una nueva coordenada y. bally (nuestra posición actual) + rise (hasta dónde nos movemos hacia arriba) es la respuesta. ¡Pero usar rise pondrá la pelota en la red cada vez! Necesitamos usar cuál sería el aumento con la pendiente que el usuario adivinó. Para obtener nuestro nuevo aumento, usaremos la estimación de la pendiente = aumento/ejecución y resolveremos el aumento.

  • En LÓGICA, haga clic en y arrastra Multiplication .
  • Cambie my_var a newrise , y reemplace 2 * 3 con slopeguess * run .

To navigate the page using the TAB key, first press ESC to exit the code editor.

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)
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)