stage.set_background_color("black")
# sprite = codesters.Point(x, y)
sprite = codesters.Point(50, 100)
sprite.set_color("green")
sprite.pen_down()
def right_key():
    sprite.move_right(20)
    # add other actions...
    
stage.event_key("right", right_key)
    t = codesters.Teacher()
func = t.find_block('def')
call = t.find_function('event_key')
try:
    downs = t.find_function('move_down')
    tval1 = downs[0][1]
    tval2 = t.get_indent_at_line(downs[0][0])
except:
    downs = "DNE"
    tval1 = "DNE"
    tval2 = "DNE"
try:
    lefts = t.find_function("move_up")
    tval3 = lefts[0][1]
    tval4 = t.get_indent_at_line(lefts[0][0])
except:
    lefts = "DNE"
    tval3 = "DNE"
    tval4 = "DNE"
try:
    rights = t.find_function('move_right')
    tval5 = rights[0][1]
    tval6 = t.get_indent_at_line(rights[0][0])
except:
    rights = "DNE"
    tval5 = "DNE"
    tval6 = "DNE"
try:
    right_event = t.find_text('right_key')
    left_event = t.find_text('left_key')
    up_event = t.find_text('up_key')
    down_event = t.find_text('down_key')
except:
    right_event = "DNE"
    left_event = "DNE"
    up_event = "DNE"
    down_event = "DNE"
t1 = TestObjective()
t1.add_success(len(func) == 4, "Great job!")
t1.add_failure(len(func) == 0, "Oops! Did you delete your right and left key events?")
t1.add_failure(len(func) < 4 and len(func) > 0, "Did you add 2 new key events?")
t1.add_failure(len(func) > len(call), "Oops! Did you delete one of your event handlers?")
t1.add_failure(len(func) < len(call), "Oops! Did you delete one of your function definition lines?")
t2 = TestObjective()
t2.add_success('sprite.' in tval1 and tval2 == 4, "Great job!")
t2.add_failure(tval1 == "DNE", "Oops! Did you delete the .move_down() command in your event?")
t2.add_failure(tval2 < 4, "Make sure your .move_down() command is indented 4 spaces in your down key event.")
t2.add_failure(tval2 > 4, "Make sure your .move_down() command is indented only 4 spaces inside your down key event.")
t3 = TestObjective()
t3.add_success('sprite.' in tval3 and tval4 == 4, "Great job!")
t3.add_failure(tval3 == "DNE", "Oops! Did you delete the .move_left() command in your event?")
t3.add_failure(tval4 < 4, "Make sure your .move_left() command is indented 4 spaces in your left key event.")
t3.add_failure(tval4 > 4, "Make sure your .move_left() command is indented only 4 spaces inside your left key event.")
t4 = TestObjective()
t4.add_success('sprite.' in tval5 and tval6 == 4, "Great job!")
t4.add_failure(tval5 == "DNE", "Oops! Did you delete the .move_right() command in your event?")
t4.add_failure(tval6 < 4, "Make sure your .move_right() command is indented 4 spaces in your right key event.")
t4.add_failure(tval6 > 4, "Make sure your .move_right() command is indented only 4 spaces inside your right key event.")
t5 = TestObjective()
t5.add_failure(len(right_event) != 2, "Oops! Do you have a right_key event handler?")
t5.add_failure(len(left_event) != 2, "Oops! Do you have a left_key event handler?")
t5.add_failure(len(up_event) != 2, "Oops! Do you have a up_key event handler?")
t5.add_failure(len(down_event) != 2, "Oops! Do you have a down_key event handler?")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4, t5])
tester.run_tests()
tester.display_first_feedback()
    
                                     
                                    
                                        
    
  
  
  - 
    
    
        Run Code
    
  
- 
        
    
        Activity Submitted!
    
    Submit Work
      
- 
          
    
            Next Activity
        
        
- 
    
    
    
    
      Stop Running Code
    
  
- 
    
  
  
  
    Show Chart
  
  
- 
    
  
  
  
    Show Console
  
  
- 
        
      
      
      
        Reset Code Editor
      
      
- 
    
    
    
    
      Codesters How To (opens in a new tab)