DEMO #1: En esta demostración, usará una variable para almacenar un número, ¡luego usará esa variable en un comando!
Una variable es un nombre que almacena un valor. ¡En este programa, vamos a usar variables para almacenar números que se generan aleatoriamente! Una instrucción de creación de variables utiliza un signo igual para conectar el nombre con el valor almacenado.
Pase el cursor sobre las partes de la declaración de creación de variables en el escenario para obtener más información sobre cada parte.
Intente hacer clic en la persona, luego haga clic en¡Corre de nuevo para ver qué cambia en el escenario!
To navigate the page using the TAB key, first press ESC to exit the code editor.
sprite = codesters.Sprite("person11", 0, -60)
sprite.set_size(.8)
#Pick a random number from 1 to 360 and store it in secret_number
secret_number = random.randint(1,360)
stage.wait(2)
sprite.turn_right(secret_number)
stage.set_axis(100)
# text = codesters.Text("text", x, y, "color")
var_name = codesters.Text("secret_number", -26, 22, "orange")
# text = codesters.Text("text", x, y, "color")
equals_sign = codesters.Text("=", 8, 22, "black")
# text = codesters.Text("text", x, y, "color")
var_value = codesters.Text(str(secret_number), 22, 22, "blue")
# circ_code = codesters.Text("codesters.Circle(0, -100, circle_radius, \"gold\")")
# circ_code.set_size(.7)
title = codesters.Text("Parts of a Variable Creation Statement", 0, 70, "black")
what_is = codesters.Text(" ", 0, 55, "black")
explanation = codesters.Text(" ", 0, 42, "black")
explanation.set_size(.7)
def mouse_move():
x = stage.mouse_x()
y = stage.mouse_y()
if y < 35 and y > 7:
if x < -2.5 and x > -55:
what_is.set_color("orange")
what_is.set_text("Name")
explanation.set_text("The name is where your program stores the value.")
elif x > -2.5 and x < 12:
what_is.set_color("black")
what_is.set_text("Equal Sign")
explanation.set_text("Connects the name to the stored value.")
elif x > 12 and x < 37:
what_is.set_color("blue")
what_is.set_text("Value")
explanation.set_text("The value stored in the variable.")
else:
what_is.set_text(" ")
explanation.set_text("Hover over the parts of the variable statement.")
# elif y > -50:
# if y > -25 and y < 25:
# what_is.set_color("purple")
# what_is.set_text("Dice")
# explanation.set_text("The dice has a numbered side that is controlled by the variable dice_roll.")
else:
what_is.set_text(" ")
explanation.set_text("Hover over the parts of the variable statement.")
stage.event_mouse_move(mouse_move)
reverse = -secret_number
def click(sprite):
sprite.say("Wheeeeee!", 2)
sprite.turn_right(reverse)
sprite.say("I just spun " + str(secret_number) + " degrees!")
# add other actions...
sprite.event_click(click)
tester = TestManager()
tester.display_success_message("Great job! Be sure to hover over each part!")
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.