stage.set_background("halfcourt")
sprite = codesters.Sprite("player4")
sprite.go_to(215, -175)
net = codesters.Sprite("basketballnet")
net.go_to(215, 175)
ball = codesters.Sprite("basketball")
x = random.randint(-100, 150)
ball.go_to(x, -25)
stage.set_gravity(10)
stage.set_bounce(.8)
ball.set_gravity_off()
net.set_gravity_off()
left_count = 0
down_count = 0
def left_key():
ball.move_left(10)
# add other actions...
global left_count
left_count += 1
stage.event_key("left", left_key)
t = codesters.Teacher()
event = t.find_text('def')
downs = t.find_text('move_down')
handler = t.find_text('event_key')
try:
tval1 = event[1][1]
tval2 = event[1][0]
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval6 = handler[1][1]
tval7 = handler[1][0]
tval8 = t.get_indent_at_line(tval7)
except:
tval6 = "DNE"
tval7 = "DNE"
tval8 = "DNE"
try:
tval3 = downs[0][1]
tval4 = downs[0][0]
tval5 = t.get_indent_at_line(tval4)
except:
tval3 = "DNE"
tval4 = "DNE"
tval5 = "DNE"
t1 = TestObjective()
t1.add_success('down_key' in tval1 and '(sprite)' not in tval1, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Down Key event?")
t1.add_failure('sprite' in tval1, "Oops! Did you add a Sprite Down Key instead? Try looking in Stage Events.")
t1.add_failure('down_key' not in tval1, "It looks like you added a different event. Try adding a Down Key event.")
t1.add_failure(tval6 == "DNE", "Oops! Did you delete the last line of your Down Key event?")
t1.add_failure(tval7 < tval4, "Make sure your Move Down command is inside your Down Key event, after the first line and before the last.")
t1.add_failure(tval8 != 0, "Make sure the last line of you event is not indented at all.")
t2 = TestObjective()
t2.add_success('ball.' in tval3 and tval5 == 4 and tval4 > tval2 and '10' in tval3, "Great job!")
t2.add_failure(tval3 == "DNE", "Did you add a Move Down command to your event?")
t2.add_failure('ball.' not in tval3, "Did you change the name in front of the Move Down command to ball?")
t2.add_failure('50' in tval3, "Did you change the nuber in the Move Down command to 10?")
t2.add_failure('10' not in tval3, "Make sure the number in parentheses after the Move Down command is 10.")
t2.add_failure(tval4 < tval2, "Make sure you place your Move Down command after the first line of the Down Key event.")
t2.add_failure(tval5 < 4, "Make sure your Move Down command is indented 4 spaces inside the Down key event.")
t2.add_failure(tval5 > 4, "Oops, you indented too far. Make sure your Move Down is 4 spaces inside your Down Key event.")
tester = TestManager()
tester.add_test_list([t1, t2])
tester.run_tests()
tester.display_first_feedback()
-
Run Code
-
Activity Submitted!
Enviar Trabajo
-
Actividad Siguiente
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)