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)
global left_count
left_count += 1
# add other actions...
stage.event_key("left", left_key)
def down_key():
ball.move_down(10)
global down_count
down_count += 1
# add other actions...
stage.event_key("down", down_key)
def space_bar():
ball.set_gravity_on()
ball.set_x_speed(left_count)
# add other actions...
stage.event_key("space", space_bar)
t = codesters.Teacher()
speed = t.find_function('set_y_speed')
try:
tval1 = speed[0][1]
tval2 = speed[0][0]
tval2 = t.get_indent_at_line(tval2)
except:
tval1 = "DNE"
tval2 = "DNE"
t1 = TestObjective()
t1.add_success(tval1.replace(' ', '') == 'ball.set_y_speed(down_count)' and tval2 == 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Set Y Speed command to your Space Bar event?")
t1.add_failure('ball.' not in tval1, "Did you change the name in front of your Set Y Speed command to ball?")
t1.add_failure('down_count' not in tval1, "Did you change the number in the Set Y Speed command to down_count?")
t1.add_failure(tval2 < 4, "Make sure you indent the Set Y Speed command 4 spaces inside the Space Bar event.")
t1.add_failure(tval2 > 4, "Make sure your Set Y Speed command is only indented 4 spaces inside the Space Bar event.")
tester = TestManager()
tester.add_test_list([t1])
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)