Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can help me complete this code, somehow I cannot let the user answer the maths questions using 'a' and 'b' buttons. from microbit import *

Can help me complete this code, somehow I cannot let the user answer the maths questions using 'a' and 'b' buttons.

from microbit import * import random import music

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

tick = Image("00000:" "00009:" "00090:" "90900:" "09000")

cross = Image("90009:" "09090:" "00900:" "09090:" "90009")

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")) correct_step = (Image.HAPPY) music.play(music.JUMP_UP) elif step_operator == 'math_step': step -= 1 correct_step = (Image.SAD) music.play(music.JUMP_DOWN) # Generate random numbers and operator for math game answer = 0 num1 = random.randint(0, 9) num2 = random.randint(0, 9) math_operator = random.choice(["+", "-"]) input_answer = 0 correct_answer = None if math_operator == '+': correct_answer = num1 + num2 elif math_operator == '-': correct_answer = num1 - num2 # Display the math question on the screen display.scroll(str(num1) + math_operator + str(num2) + " = ?") sleep(1000) display.clear()

# Wait for user input user_answer = int(input("Enter your answer: "))

# User input if input(button_a.was_pressed()): input_answer += 1 display.show(str(user_answer)) if button_b.was_pressed(): # Check if the answer is correct if input_answer == correct_answer: display.show(Image( "00000:" "09900:" "99999:" "99999:" "90090")) display.show(tick) answer += 1 else: display.show(Image( "90090:" "99999:" "99999:" "09900:" "00000")) display.show(cross) display.scroll("Game Over!") display.scroll("Your score: " + str(answer)) sleep(1000) display.clear() display.show(step_operator) sleep(1000) display.scroll('End of the road, The Turle 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

Recommended Textbook for

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

a virtual machine is essentially another name for

Answered: 1 week ago

Question

2. Outline the business case for a diverse workforce.

Answered: 1 week ago