Python - Cell Phone Number Pad Input

Here is the first version of a little python program I made that will translate input from a cellphone text pad or a number pad to text.

It’s pretty darn simple.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import string as st
nar = []
 
nar.append([' '])
nar.append(['!','@','#','$','%','^','&','*','(',')'])
nar.append(['a','b','c'])
nar.append(['d','e','f'])
nar.append(['g','h','i'])
nar.append(['j','k','l'])
nar.append(['m','n','o'])
nar.append(['p','q','r','s'])
nar.append(['t','u','v'])
nar.append(['w','x','y','z'])
 
bigres = ""
while 1:
        inp = raw_input("")
        #print inp
        inp0 = int(inp[0])
        #print inp0
        inpc = st.count(inp,inp[0])
        inpcmod = inpc % len(nar[inp0])
        inpc = inpcmod -1
        #print inpc
        inpResult = nar[inp0][inpc]
        print bigres + " + " + inpResult
        bigres += inpResult

Comments (1)

DallasAugust 16th, 2008 at 10:13 pm

Hey you mentioned that it would convert from cell pad or number pad. Keep in mind that those two aren’t the same (they’re inverted forms of one another).

Also, happy birthday!

Leave a comment

Your comment