Well there are a few ways to do it. Preferably i would use a dictionary but as we cant here is another way:
import string
number = raw_input("Please enter the number:").lower()
n_list = list(number)
for enu,f in enumerate(number):
if f in string.ascii_lowercase:
i = string.ascii_lowercase.index(f)+2
i /= 3
if i == 0:
i +=1
n_list[enu] = '123456789'[i]
print ''.join(n_list)
an example output:Please enter the number:1800-testing
1800-8378463
Wow.. that worked better then i thought it would.
Enjoy!
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
As has already been hinted, you are probably expected to use 2 lists. The first contains letters and the second contains the number for the corresponding letter. You could also use a list of lists, with each sub-list containing the letter and number, but that is probably more than you can wrap your head around at this point. Do whatever makes sense to you. There are only 26 letters in the English alphabet, so the list is very small, which means that any method with take about the same amount of time. Code something, and append it to the thread for additional help.
woooee
Nearly a Posting Maven
2,454 posts since Dec 2006
Reputation Points: 777
Solved Threads: 714