Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python 3 Phone Numbers Program I need help figuring out how to get a program tha

ID: 3831650 • Letter: P

Question

Python 3 Phone Numbers Program

I need help figuring out how to get a program that takes the last 4 digits of 1.800.555 phone numbers and converting it into letters to show all the possible combinations. So far the program displays 4 of a certain number and one of their corresponding letters but I need it to iterate through all the possible combinations. There should be 456,976 combinations. Here is my code so far:

alph_num_dict = {'a': '2', 'b': '2', 'c': '2',

             'd': '3', 'e': '3', 'f': '3',

             'g': '4', 'h': '4', 'i': '4',

              'j': '5', 'k': '5', 'l': '5',

             'm': '6', 'n': '6', 'o': '6',

             'p': '7', 'q': '7', 'r': '7', 's': '7',

             't': '8', 'u': '8', 'v': '8',

             'w': '9', 'x': '9', 'y': '9', 'z': '9'}

for letter, digit in alph_num_dict.items():

    print("1.800.555." + str(digit) + str(digit) + str(digit) + str(digit), end=" ")

    print("    1.800.555." + str(letter) + str(letter) + str(letter) + str(letter))

Explanation / Answer

You can use permutation function in this program

alph_num_dict = {'a': '2', 'b': '2', 'c': '2',

             'd': '3', 'e': '3', 'f': '3',

             'g': '4', 'h': '4', 'i': '4',

              'j': '5', 'k': '5', 'l': '5',

             'm': '6', 'n': '6', 'o': '6',

             'p': '7', 'q': '7', 'r': '7', 's': '7',

             't': '8', 'u': '8', 'v': '8',

             'w': '9', 'x': '9', 'y': '9', 'z': '9'}

from itertools import permutations

all_numbers=permutations(alph_num_dict, 4):

for number in all_numbers:

#TODO:Iterate through all _numbers and do translation