Question: IN PYTHON! I got an answer but it used a list instead of a dictionary, how would I modifify it so that it uses a

IN PYTHON!

I got an answer but it used a list instead of a dictionary, how would I modifify it so that it uses a dictionary object instead of list objects.

ex: d = {'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'}

instead of:

d=["abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"]

here is the code, I'm not allowed to import any library functions:

d=["abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"] while(True): s = input("ENTER a telephone NUMBER:-") l = len(s)#calculating length of the string if(l==0):#if it is a null string then loop breaks... break s.lower()#converting alphabets to lower characters... c=0 for i in range(l): if(s[i].isalnum()): c=c+1#calculating the length of the given number ii=0#variable to check how '-' are needed to print between numbers.. t=0 if(c==10 or c==7):#checking whether valid number or not....if valid then for i in range(l): if(s[i].isalnum()):#checking alphanumberic or not..to check whether to print or not.. if(s[i].isalpha()):#if it is alpha then needed to convert to numberic.. for j in range(8): if (s[i].lower() in d[j]): print (j+2,end='')#printing number.. ii=ii+1 break else : print (s[i],end='')#printing number.. ii=ii+1 if(ii==3 and t<2):#checking how '-' are needed to print between numbers.. if(c==7): if(t<1): print('-',end='') else: print('-',end='') ii=0 t=t+1 else : print ("Invalid number!")#if it is not a valid number.... print (" ")

How do I fix the above code so that it displays the following results:

>>> getNumber()

Enter a telephone number: 612.got.milk

Numeric telephone number is: 612-468-6455

Enter a telephone number: 612.not.milky

Invalid number!

Enter a telephone number: Voo doo Dude

Numeric telephone number is: 866-366-3833

Enter a telephone number: got#milk

Numeric telephone number is: 468-6455 Enter a telephone number:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!