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:
pass
# add other actions...
stage.event_click(click)
t = codesters.Teacher()
loops = t.find_block('for')
defs = t.find_text('def')
handler = t.find_text('event_click')
circle_text = t.find_text('Circle')
circle_params = t.get_parameters_for_function('Circle')
try:
tval1 = int(loops[1][0])
except:
tval1 = 0
try:
tval2 = int(defs[0][0])
except:
tval2 = 0
try:
tval3 = int(handler[0][0])
except:
tval3 = 0
try:
tval4 = t.get_indent_at_line(tval1)
except:
tval4 = -1
try:
tval5 = loops[1][1].replace(" ", "")
except:
tval5 = "DNE"
try:
tval6 = circle_params[0]
tval6b = t.get_indent_at_line(circle_text[0][0])
except:
tval6 = "DNE"
tval6b = "DNE"
t1 = TestObjective()
t1.add_success(tval1 != 0 and tval2 < tval1 < tval3, "Great Job!")
t1.add_failure(tval1 == 0, "Did you add a Loop with Range?")
t1.add_failure(tval1 < tval2, "Oops! Make sure your loop is after the def click(): line!")
t1.add_failure(tval3 < tval2, "Oops! Make sure your loop is before the .event_click() line!")
t2 = TestObjective()
t2.add_success(tval1 != 0 and tval4 == 8 and tval5 == 'forcounterinrange(amount):', "Great job!")
t2.add_failure(tval4 == -1, "Did you drag out a Loop with Range command?")
t2.add_failure(tval4 != 8, "Oops! Make the new loop is indented twice!")
t2.add_failure('(5)' in tval5, "Did you change (5) to (amount)?")
t3 = TestObjective()
t3.add_success(tval6 == ['x', 'y', '10', 'color'] and tval6b == 12, "Great job!")
t3.add_failure(tval6 == "DNE", "Did you add a circle in your new loop?")
t3.add_failure(tval6 == ['0', '0', '100', '"blue"'], "Did you change the .Circle() arguments?")
t3.add_failure(tval6 != "DNE" and tval6 != ['x', 'y', '10', 'color'] and tval6 != ['0', '0', '100', '"blue"'], "Did you change the .Circle() arguments correctly?")
t3.add_failure(tval6b != 12, "Oops! Make sure .Circle() is indented 3 times!")
################################################
# 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, t2, t3])
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)