Site icon Altitude Foundation

Micro Challenge #41 – Proofing a program

Welcome to the forty-first of Altitude Foundation’s #MicroChallenges2020

Today’s challenge will help you practice spotting sequencing errors

What’s a Micro Challenge?

These challenges are short activities to help you develop, revise or refresh your coding skills, posted every Monday, Wednesday and Friday.

Micro Challenge #41

This week, we are exploring error-spotting. 

The Challenge:

Today’s challenge focuses on spotting typing errors. Below are three sequences, one pseudocode, one Python and  one JavaScript with sequencing errors. Can you spot the errors and make the code usable?

  1. A vote tallying programme (pseudocode)

vote tally a ← 0

vote tally b ← 0

“Enter your voter”

Press A ← USERINPUT

“Thank you for your vote”

OR

Press B ← USERINPUT 

“Thank you for your vote”

IF press a, vote tally a ← add 1

IF press b, vote tally b ← add 1

“The new tally is” + vote tally a + vote tally b

  1. A sock matching game (JavaScript)

input.onButtonPressed(Button.A, function () {   

    basic.showSting(“1st!”)

    basic.pause(500)

    basic.showString(“” + (Socks_1[index]))

    basic.pause(500)

    basic.showString(“2nd”)

    basic.pause(500)

    basic.showString(“” + (Socks_2index_2))

    }

 if (Socks_1[index] == Socks_2index_2) {

        Basic.showString(“Matched pair”)

        Basic.showString(“Try Again”)

        Basic.clearScreen()

    } else {

        Basic.showString(“Hurra!!!”)  

})

  1. A programme which picks a song for you to sing to time washing your hands

from microbit import *

import random

answers = [

    “Any Dream Will Do”

    “Take On Me”

    “Do-Re-Mi”

    “All Star”

    “Never Gonna Give You Up”

    “Mr Brightside”

    “Africa”

]

while True:

    display.show(“Wash Your Hands?”)

    if accelerometer.was_gesture(“shake”):

    display.clear()

    sleep(1000)

    display.scroll(random.choice(answers))

    display.scroll(“1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19”)

    display.show(Image.YES)

Review it:

Advanced:

Share it

We would love to see what you have created! Please send any pictures, videos, or files of your activities to us – either via Facebook, Twitter or Instagram  using #MicroChallenges2020 or to challenges@altitudefoundation.org. If you are emailing them to us, please let us know if you are happy for us to share your stuff on our social media platforms (with credit, of course). 

Exit mobile version