VISTA PREVIA: Antes de comenzar a crear nuestro primer programa, veamos un ejemplo.

  • Este programa crea una pelota y una red, luego dibuja una línea entre ellos.
  • Se le pide que estime la pendiente de la línea.
  • Si su conjetura está cerca, ¡puntúe! Si no... ¡mira por dónde va la pelota! La pendiente real se mostrará en la pantalla.
  • Hacer clic Ejecutar para intentarlo de nuevo, y Enviar y Siguiente para continuar.

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

#Set the grid and background stage.set_axis(100) stage.create_grid_overlay(10, "grey") stage.set_background("soccerfield") #Create coordinates for ball, create ball ballx = -90 bally = random.randint(-100, 100) ball = codesters.Sprite("soccerball", ballx, bally) #Create coordinates for net, create net netx = 80 nety = random.randint(-100, 100) net = codesters.Sprite("soccernet", 80,nety) net.flip_right_left() #Draw line between ball and net line = codesters.Line(-90, bally, 80, nety, "blue") slopeguess = float(line.ask("What is the slope of the line?")) #Calculate slope rise = nety-bally run = netx-ballx slope = rise/run #Display slope # sprite = codesters.Text("text", x, y) sprite = codesters.Text(slope, 0, 30) #Calculate new point for ball newrise = (slopeguess*run) endy = bally + newrise ball.glide_to(netx, endy)
  • Run Code
  • Enviar Trabajo
  • Actividad Siguiente
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)