You are working at a lower league football stadium and you’ve been asked to automate the scoreboard.

The referee will shout out the score, you have already set up the voice recognition module which turns the ref’s voice into a string, but the spoken score needs to be converted into a pair for the scoreboard!

e.g. “The score is four nil” should return [4,0]

Either teams score has a range of 0-9, and the ref won’t say the same string every time e.g.

“new score: two three”

“two two”

“Arsenal just conceded another goal, two nil”

Create a function which will return the array of scores.

def scoreboard(string):
    score = ['nil', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']
    score_arr = []
    string_list = string.split(' ')
    for word in string_list:
        if word in score:
    return score_arr

These are the steps to create the score array.

  1. Split the string into a list.
  2. Iterate through the list.
  3. Find the scores and append them to the array then return.
Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *