stage.set_axis(11) #sprite = codesters.Line(x-start, y-start, x-end, y-end, "color") line = codesters.Line(-11, 0, 11, 0, "blue") for counter in range(-10, 11): point = codesters.Point(counter, 0) text = codesters.Text(str(counter), counter, 1, "blue") text.set_size(.7) number1 = random.randint(-10, 10) number2 = random.randint(-10, 10) display1 = codesters.Display(number1, -7, 6) display2 = codesters.Display(number2, -4, 6) # sprite = codesters.Triangle(x, y, size, "color") marker1 = codesters.Triangle(number1, -.5, .75, "blue") marker2 = codesters.Triangle(number2, -.5, .75, "gold") asker = codesters.Sprite("person1", 0, -12) def left_key(): marker1.move_left(1) # add other actions... stage.event_key("left", left_key) def right_key(): marker1.move_right(1) # add other actions... stage.event_key("right", right_key) def collision(sprite, hit_sprite): marker1.set_color('green') hit_sprite.set_color("green") text = codesters.Text("Press the space bar to guess the number!", 0, 3 ) # add any other actions... marker1.event_collision(collision) def space_bar(): guess = int(asker.ask("What do I need to add to number1 to get to number2?")) if guess == (number2 - number1): # text = codesters.Text("text", x, y, "color") text = codesters.Text("You got it!", 0, -3, "green") elif guess == -(number2 - number1): text = codesters.Text("Oops! Remember, a move to the right is positive and a move to the left is negative.", 0, -3, "black") else: text = codesters.Text("Sorry, that's not it. Try using the arrow keys to count up or down.", 0, -3, "red") # add other actions... stage.event_key("space", space_bar)
  • Run Code
  • Show Console
  • Codesters How To (opens in a new tab)