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: score_arr.append(score.index(word)) return score_arr
These are the steps to create the score array.
- Split the string into a list.
- Iterate through the list.
- Find the scores and append them to the array then return.
from Planet Python
via read more
No comments:
Post a Comment