Challenge 3: Debug the program so that a blue circle appears on the stage if any only if you choose circle.
Click Run and type square into the ask bubble to see the error on the stage. Debug the program then click Run and type in circle again to check your work. Hint: Commands that run as part of an if statement should have a yellow block ···· in front of them to show they are indented 4 spaces.
To navigate the page using the TAB key, first press ESC to exit the code editor.
sprite = codesters.Sprite("snowman")
sprite.go_to(-140, -125)
choice = sprite.ask("Square or circle?")
if choice == "square":
sprite.say("square!")
sprite = codesters.Square(50, 100, 75, "green")
if choice == "circle":
sprite.say("circle!")
sprite = codesters.Circle(50, 0, 100, "blue")
t = codesters.Teacher()
try:
params = t.find_block("if")
tval1a = params[1][1]
tval1b = t.get_indent_at_line(params[1][0])
except:
tval1a = "DNE"
tval1b = "DNE"
try:
params = t.find_function("Circle")
tval2a = params[0][1].lower()
tval2b = t.get_indent_at_line(params[0][0])
except:
tval2a = "DNE"
tval2b = "DNE"
# print tval1a, tval1b
t1 = TestObjective()
t1.add_success(tval2b == 4, "Great job debugging the program!")
t1.add_failure(tval2b == 0, "Did you put the circle command inside the if statement?")
t1.add_success(tval1a == "DNE" or tval1b == "DNE", "Did you delete the if statement?")
t1.add_failure(tval1a == "DNE" or tval1b == "DNE", 'Did you delete the circle command?')
tester = TestManager()
tester.add_test_list([t1])
tester.run_tests()
tester.display_first_feedback()
Run Code
Activity Submitted!
提交作品
下个活动
Stop Running Code
Show Chart
Show Console
Reset Code Editor
Codesters How To (opens in a new tab)