stage.set_background("underwater")
score = 0
score_board = codesters.Display(score)
weak_pws = ["password", "password123", "hello1", "snuffles", "123456"]
strong_pws = ["GgbvTa581!@", "@Mjrc0olguy!", "007jmSB0nd!", "108turt!es762", "Avv3SoMe!305"]
all_pws = weak_pws + strong_pws
# text = codesters.Text("text", x, y, "color")
password = codesters.Text("password", 100, 200, "red")
def interval():
# add any other actions...
rand_x = random.randint(-225, 225)
rand_y = random.randint(-225, 225)
rand_pw = random.choice(all_pws)
password.set_text(rand_pw)
password.go_to(rand_x, rand_y)
stage.event_interval(interval, 2)
t = codesters.Teacher()
events = t.find_block('def')
handler = t.find_function('event_click')
try:
tval1 = events[1][1]
tval2 = t.get_indent_at_line(events[1][0])
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = t.find_function('say')[0][0]
except:
tval3 = "DNE"
try:
tval4 = t.get_indent_at_line(t.find_text('global')[0][0])
tval4a = t.find_text('global')[0][1]
except:
tval4 = "DNE"
tval4a = "DNE"
try:
tval5 = handler[0][1]
tval6 = t.get_indent_at_line(handler[0][0])
except:
tval5 = "DNE"
tval6 = "DNE"
t1 = TestObjective()
t1.add_success('click(sprite)' in tval1 and tval2 == 0, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add a Sprite Click event?")
t1.add_failure('click()' in tval1, "Oops! Make sure you add a Sprite Click event, not a stage event!")
t1.add_failure('click(sprite)'not in tval1, "Did you add a Sprite Click event to your program?")
t1.add_failure(tval2 > 0, "Make sure your new event is outside your interval event and not indented at all!")
t2 = TestObjective()
t2.add_failure(tval3 != "DNE", "Oops! Make sure you delete the Say command from the Click event!")
t3 = TestObjective()
t3.add_success(tval4 == 4 and 'score' in tval4a, "Great job!")
t3.add_failure(tval4 == "DNE", "Did you add a global variable to your Sprite Click event?")
t3.add_failure('score' not in tval4a, "Did you change the name of your global variable to score?")
t3.add_failure(tval4 < 4, "Oops! Make sure your Global Variable is indented inside your Sprite Click event!")
t4 = TestObjective()
t4.add_success('password.event_click(click)' in tval5 and tval6 == 0, "Great job!")
t4.add_failure(tval5 == "DNE", "Oops! Did you delete your event handler?")
t4.add_failure('password.' not in tval5, "Did you change the name in front of the last line of your click event to password?")
t4.add_failure('event_click(click)' not in tval5, "Oops! Make sure you don't change the last line of the event, except for the first word!")
t4.add_failure(tval6 > 0, "Make sure your last line is not indented inside your event!")
tester = TestManager()
tester.add_test_list([t1, t2, t3, t4])
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)