Skip to content

活動

Times tables tester

初學者 | MakeCode, Python | LED 螢幕, 按鈕 | 4 Quality education, 乘法, 變數, 隨機化

步驟1:製作

它是什麼?

Test your knowledge of times tables with this project.

這兩支影片為您示範了製作內容和編碼方法:

運作方式

  • The program uses two variables called “a” and “b” to store random numbers.
  • Variables store numbers or values that can change in a computer program.
  • Press button A to generate a random number between 1 and 12 for the variable “a” and to show it on the LED display. Press button B to generate another random number between 1 and 12 for “b” and to show it on the LED display.
  • Shake the micro:bit to find out what the product is - that's what the answer would be if the numbers were multiplied together. This part of the program works using the multiplication block from the maths menu in MakeCode.
  • You can use this project in a competitive two-player game, where the two random numbers are read out and each player must shout out the correct answer first to win a point.

你需要的東西

  • micro:bit (或,MakeCode simulator)
  • 電池組(選配)

步驟2:編碼

1from microbit import *
2import random
3a = 0
4b = 0
5
6# Shake the micro:bit to see the answer in the Python version
7while True:
8    if accelerometer.was_gesture('shake'):
9        display.scroll(a*b)
10    if button_a.was_pressed():
11        a = random.randint(1, 12)
12        display.scroll(a)
13    if button_b.was_pressed():
14        b = random.randint(1, 12)
15        display.scroll(b)

步驟3:進階

  • Adjust the program so that it helps you to learn square numbers.
  • If you are playing the two-player game, create another program on a different micro:bit to keep track of the players' scores.
  • Use various inputs in this program to trigger different sound effects, which you can play when players give a correct or incorrect answer.