def return_trajectory(speed, angle):
radians = math.radians(angle)
x_velocity = speed * math.cos(radians)
y_velocity = speed * math.sin(radians)
return (x_velocity, y_velocity)
stage.set_background_color("black")
amount = 10
speed = 5
color_list = ["purple", "yellow", "red"]
stage.disable_all_walls()
def click():
x = stage.click_x()
y = stage.click_y()
particle_list = []
for color in color_list:
for counter in range(amount):
sprite = codesters.Circle(x, y, 10, color)
particle_list.append(sprite)
angle = 0
for count, p in enumerate(particle_list):
count += 1
# add other actions...
stage.event_click(click)
t = codesters.Teacher()
call = t.find_text('return_trajectory')
wrong_call = t.find_text('my_function')
try:
tval1 = call[1][1].lower().replace(' ', '')
tval2 = t.get_indent_at_line(call[1][0])
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = wrong_call[0][1]
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval2 == 8 and tval1 == 'speed_values=return_trajectory(speed,angle)', "Great job!")
t1.add_failure(tval1 == "DNE" and tval3 == "DNE", "Did you add Call Parameters into Variable?")
t1.add_failure(tval1 == "DNE" and tval3 != "DNE", "Did you change my_function to return_trajectory?")
t1.add_failure(tval2 != 8, "Make sure the new line of code is indented twice!")
t1.add_failure('my_parameter1' in tval1, 'Did you replace parameter1 with speed?')
t1.add_failure('my_parameter2' in tval1, 'Did you replace parameter2 with angle?')
t1.add_failure('my_var=' in tval1, 'Did you replace my_var with speed_values?')
################################################
# Pass test code
# - set pass_required to True if pass is required to prevent bad input error
# - include tpass before t1 in the test list
pass_required = False
passes = t.find_text("pass")
num_pass_only = 0
for p in passes:
if p[1].lower().replace(' ','') == "pass":
num_pass_only += 1
tpass = TestObjective()
if not pass_required:
tpass.add_success(num_pass_only == 0, "Great job!")
tpass.add_creative(num_pass_only > 0, "Great job! Feel free to delete pass statements now.")
################################################
tester = TestManager()
tester.add_test_list([tpass, t1])
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)