Phone numbers and PIN codes can be easier to remember when you find words that spell out the number on a standard phone keypad. For example, instead of remembering the combination 2633, you can just think of CODE. Write a recursive function that, given a number, yields all possible spellings (which may or may not be real words).

Respuesta :

Answer:

Explanation:

The following is written in Python and the code first creates a simulated keypad with all the characters. Then the function detects the number passed as an input argument and outputs all the possible spelling combinations.

keypad = {

   '2': 'abc',

   '3': 'def',

   '4': 'ghi',

   '5': 'jkl',

   '6': 'mno',

   '7': 'pqrs',

   '8': 'tuv',

   '9': 'wxyz',

}

def word_numbers(number):

 number = str(number)

 wordList = ['']

 for char in number:

   letters = keypad.get(char, '')

   wordList = [prefix+letter for prefix in wordList for letter in letters]

 return wordList

Ver imagen sandlee09
ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE