STEP 11: Let's use a random x-coordinate to set the position of the falling food!
Change the name of the random integer variable from my_var to rand_x.
Change the range in random.randint() from (1,10) to (-250,250).
Now, your program creates and stores a random number between -250 and 250 every 2 seconds! We will use that number to create a new piece of fish food and place it on the stage every 2 seconds.
To navigate the page using the TAB key, first press ESC to exit the code editor.
t = codesters.Teacher()
rand_range = t.get_parameters_for_function('randint')
try:
tval1 = t.find_function('turn_left')[0][1]
except:
tval1 = "DNE"
try:
tval2 = int(rand_range[0][0])
tval3 = int(rand_range[0][1])
except:
tval2 = "DNE"
tval3 = "DNE"
try:
tval4 = t.get_indent_at_line(t.find_function('randint')[0][0])
except:
tval4 = -1
try:
tval5 = t.find_function('randint')[0][1]
except:
tval5 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == "DNE", "Great job!")
t1.add_failure(tval1 != "DNE", "Did you delete the Turn Left command from your Interval Event?")
t2 = TestObjective()
t2.add_success(tval2 == -250 and tval3 == 250, "Great job!")
t2.add_failure(tval2 == "DNE", "Did you add a Random Integer command inside your interval event?")
t2.add_failure((tval2 == 1 or tval3 == 10), "Did you change the range in the .randint() command?")
t2.add_failure(tval4 < 4, "Make sure you indent your Random Integer command inside your interval event.")
t2.add_failure(tval4 > 4, "Make sure you indent your Random Integer command only 4 spaces inside your interval event.")
t2.add_creative((tval2 != 1 and tval3 != 10) and (tval2 != -250 or tval3 != 250), "That's a good range too!")
t3 = TestObjective()
t3.add_success('rand_x' in tval5, "Great job!")
t3.add_failure(tval5 == "DNE", "Did you delete the random integer from your Interval Event?")
t3.add_failure('my_var' in tval5, "Did you rename the random integer variable?")
t3.add_failure('rand_x' not in tval5, "Did you rename the random integer variable correctly?")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
Are you already running a Codesters project in another tab or window?
Micro:bit can only connect to one web page at a time.
Try stopping other Codesters projects or closing
other tabs or windows that may be using your Micro:bit.
If that doesn't fix the problem try disconnecting your Micro:bit,
reloading this page, and reconnecting your Micro:bit.