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)
def click(sprite):
global score
pw_text = password.get_text()
# add other actions...
password.event_click(click)
t = codesters.Teacher()
try:
tval1 = t.find_block('if')[0][1].replace(' ' ,'')
tval2 = t.get_indent_at_line(t.find_block('if')[0][0])
except:
tval1 = "DNE"
tval2 = "DNE"
try:
tval3 = t.find_text('-=')[0][1].replace(' ', '')
tval4 = t.get_indent_at_line(t.find_text('-=')[0][0])
except:
tval3 = "DNE"
tval4 = "DNE"
#print tval1, tval2, tval3, tval4
t1 = TestObjective()
t1.add_success(tval1 == 'ifpw_textinweak_pws:' and tval2 == 4, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add an if in command to your Click Event?")
t1.add_failure('pw_text' not in tval1, "Did you change the test value to pw_text?")
t1.add_failure('"pw_text"' in tval1, "Oops! Don't put the variable name in quotes.")
t1.add_failure('weak_pws' not in tval1, "Did you change the test list to weak_pws?")
t1.add_failure('weak_pwsinpw_text' in tval1, "Oops! It looks like you mixed up the test value with the test list. Change the order.")
t1.add_failure(tval2 < 4, "Make sure your if statement is indented inside the Click Event.")
t1.add_failure(tval2 > 4, "Oops! Make sure your if statement is only 4 spaces inside your click event!")
t2 = TestObjective()
t2.add_success(tval3 == 'score-=1' and tval4 == 8, "Great job!")
t2.add_failure(tval3 == "DNE", "Did you add an Subtract from Variable command to your Click Event?")
t2.add_failure('score' not in tval3, "Did you change the variable to in your Subtract from Variable command to score?")
t2.add_failure('+=' in tval3, "Oops! Did you add a Add to Variable instead?")
t2.add_failure(tval4 < 8, "Make sure your Subtract from Variable command is indented 4 spaces inside your if statement.")
t2.add_creative('1' not in tval3, "That's a good amount of points to deduct too!")
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)