stage.set_background("underwater")
score = 0
score_board = codesters.Display(score)
weak_pws = ["password", "password123", "123456", "hello1", "snuffles", "emma2003"]
strong_pws = ["GgbvTa581!@", "@Mjrc0olguy!", "007jmSB0nd!", "108turt!es762", "Avv3SoMe!305"]
all_pws = strong_pws + weak_pws
password = codesters.Text("password", 100, 200, "red")
def interval():
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, 3)
def click(sprite):
global score
pw_text = password.get_text()
if pw_text in weak_pws:
score -= 1
score_board.update(score)
password.event_click(click)
t = codesters.Teacher()
update = t.find_function('update')
try:
tval1 = t.find_block('if')[1][1].replace(' ' ,'')
tval2 = t.get_indent_at_line(t.find_block('if')[1][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"
try:
tval5 = update[1][1]
tval6 = t.get_indent_at_line(update[1][0])
except:
tval5 = "DNE"
tval6 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == 'ifpw_textinstrong_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('strong_pws' not in tval1, "Did you change the test list to strong_pws?")
t1.add_failure('strong_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 Add to Variable command to your Click Event?")
t2.add_failure('score' not in tval3, "Did you change the variable to in your Add to Variable command to score?")
t2.add_failure('-=' in tval3, "Oops! Did you add a Subtract from Variable instead?")
t2.add_failure(tval4 < 8, "Make sure your Add to 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 add too!")
t3 = TestObjective()
t3.add_success('scoreboard.(score)' in tval5 and tval5 == 8, "Great job!")
t3.add_failure(tval5 == "DNE", "Did you add an Update Display command?")
t3.add_failure('score_board.' not in tval5, "Did you change the name in front of your update command to score_board?")
t3.add_failure('(score)' not in tval5, "Did you change the variable inside the Update Display command to score?")
t3.add_failure(tval6 < 8, "Make sure you indent your Update Display command inside your if statement.")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
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)