Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Got errors: what to change? micro:bit python syntaxError: invalid syntax on this code: from microbit import * import random import music step = 0 stop_steps

Got errors: what to change?

micro:bit python syntaxError: invalid syntax on this code:

from microbit import * import random import music

step = 0 stop_steps = 0 step_operator = random.choice(["move_step", "math_step"]) correct_step = None

display.scroll("Welcome Savior, Start to make your first step!" , 65) sleep(1000) display.show(Image( "09900:" "99999:" "99999:" "90090:" "00000")) sleep(500) display.show(Image( "00000:" "09900:" "99999:" "99999:" "90090")) sleep(1000)

while stop_steps < 11: if accelerometer.was_gesture('shake'): stop_steps = stop_steps + 1 if step_operator == 'move_step': step += 1 display.show(Image( "09900:" "99999:" "99999:" "90090:" "00000")) sleep(500) display.show(Image( "00000:" "09900:" "99999:" "99999:" "90090")) music.play(music.JUMP_UP) elif step_operator == 'math_step': step -= 1 music.play(music.JUMP_DOWN) # Generate random numbers and operator for math game user_answer = 0 num1 = random.randint(0, 9) num2 = random.randint(0, 9) math_operator = random.choice(["+", "-", "*"]) if math_operator == '+': correct_answer = num1 + num2 elif math_operator == '-': correct_answer = num1 - num2 elif math_operator == '*': correct_answer = num1 * num2 # Display the math question on the screen question = str(num1) + math_operator + str(num2) + " = ?" display.scroll(question) correct_answer = eval(question) sleep(1000) display.clear()

# User input while not button_b.is_pressed(): if button_a.is_pressed(): user_answer += 1 display.show(str(user_answer)) sleep(1000)

# Check if the answer is correct if user_answer == correct_answer: display.show(Image( "00000:" "09900:" "99999:" "99999:" "90090")) step_operator = "move_step" else: display.show(Image( "90090:" "99999:" "99999:" "09900:" "00000")) display.scroll("Game Over!") display.clear() display.show(step_operator) sleep(1000) display.scroll('End of the road, The Turtle Save. Congratulations!', 65) music.play(music.ENTERTAINER)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

b. Where did they come from?

Answered: 1 week ago

Question

c. What were the reasons for their move? Did they come voluntarily?

Answered: 1 week ago

Question

5. How do economic situations affect intergroup relations?

Answered: 1 week ago