1. Practice tasks 1 Answers

Tasks

  1. Write code to repetitively show ‘Hello’, one character at a time.

  2. Write code to repetitively scroll ‘microbit’.

  3. Write code to repetitively display a heart and a giraffe.

  4. Write code to repetitively display 3 different shapes using a list.

  5. Write code to repetitively scroll the numbers 1 to 9 using a for-loop.

  6. Write code to repetitively scroll the numbers 5 to 0 using a for-loop.

  7. Write code to repetitively scroll the numbers from the list 2, 3, 5, 7, 11, 13, 17, 19 via a for-loop.

  8. Write code to repetitively scroll the numbers 1 to 9 using a for-loop using the range function.

  1. Write code to repetitively show ‘Hello’, one character at a time.

from microbit import *

while True:
    display.show('Hello')

  1. Write code to repetitively scroll ‘microbit’.

from microbit import *

while True:
    display.scroll('microbit')

  1. Write code to repetitively display a heart and a giraffe.

from microbit import *

while True:
    display.show(Image.HEART)
    sleep(50)
    display.show(Image.GIRAFFE)
    sleep(50)

  1. Write code to repetitively display 3 different shapes using a list.

from microbit import *

while True:
    display.show([Image.SQUARE, Image.DIAMOND, Image.TRIANGLE])

  1. Write code to repetitively scroll the numbers 1 to 9 using a for-loop.

from microbit import *

while True:
    for num in range(1, 10):
        display.scroll(num, delay=50)

  1. Write code to repetitively scroll the numbers 5 to 0 using a for-loop.

from microbit import *

while True:
    for num in range(5, -1, -1)
        display.scroll(num, delay=50)

  1. Write code to repetitively scroll the numbers from the list 2, 3, 5, 7, 11, 13, 17, 19 via a for-loop.

from microbit import *

num_list = [2, 3, 5, 7, 11, 13, 17, 19]
while True:
    for num in num_list:
        display.scroll(num, delay=50)

  1. Write code to repetitively scroll the numbers 1 to 9 using a for-loop using the range function.

from microbit import *

while True:
    for num in range(1,10):
        display.scroll(num, delay=50)