Answer to Question #198300 in Python for reeeeegeg

Question #198300

The link below is the question

I already try coding it but I can't come up with the output. Can you please help me with it and correct it.

I needed it already. Thank you.


https://www.chegg.com/homework-help/questions-and-answers/create-python-program-would-perform-given-description-program-description-different-countr-q78177521

First part of code:

dict1 = {'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}


def convert(word):

  x = 0

  for i in range(0,len(word)):

    ch = word[i]

    x = x * 10 + dict1[ch]

    return x


1
Expert's answer
2021-05-25T17:40:16-0400
dict1 = {'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}


def convert(word):
    x = 0
    for i in range(0, len(word)):
        ch = word[i]
        x = x * 10 + dict1[ch]
    return x



n = int(input())


words = []


T9 = []
for i in range(0, n):
    words.append(input())
    T9.append(convert(words[i]))

cases1 = []

t = int(input())
for i in range(0, t):
    cases1.append(input())

for i in range(0, t):

    x = cases1[i].split(' ')


    y = 1
    print("Message #", (i + 1), ":", end=" ")
    for j in x:
        y = y * T9.count(int(j))

    if y == 0:
        print("not a valid text")

    elif y != 1:
        print("There are ", y, " possible messages")


    else:
        for j in x:
            print(words[T9.index(int(j))], end=" ")
        print()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS