第 16 步:为了计算我们的球应该去哪里,我们需要一个新的 y 坐标。 bally (我们当前的位置)+ rise (我们向上移动多远)就是答案!但是每次使用rise都会将球入网!我们需要使用用户猜测的斜率的上升幅度。为了获得新的上升,我们将使用坡度猜测 = 上升/运行并求解上升!

  • 在逻辑中,单击并拖出Multiplication
  • newrise my_var并将2 * 3替换为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
  • 提交作品
  • 下个活动
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)