-
Notifications
You must be signed in to change notification settings - Fork 0
/
T9Typing.py
46 lines (44 loc) · 1.31 KB
/
T9Typing.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys
numDict = {'a': 2, 'b': 22, 'c': 222,
'd': 3, 'e': 33, 'f': 333,
'g': 4, 'h': 44, 'i': 444,
'j': 5, 'k': 55, 'l': 555,
'm': 6, 'n': 66, 'o': 666,
'p':7, 'q': 77, 'r': 777, 's': 7777,
't': 8, 'u': 88, 'v': 888,
'w': 9, 'x': 99, 'y': 999, 'z': 9999,
' ': 0}
def lettersToT9():
lines = input()
inputs = []
try:
for _ in range(int(lines)):
inputs.append(input())
except:
print("Wrong")
sys.exit()
lastPrint = 0
for phrase in inputs:
print(f"Case #{inputs.index(phrase) + 1}:", end=" ")
for letter in phrase:
if lastPrint == str(numDict[letter])[0]:
print(" ", end="")
print(numDict[letter], end="")
lastPrint = str(numDict[letter])[0]
print(" ")
def t9ToLetters():
nums = input().split()
numbers = (int(num) for num in nums)
letterDict = {v:k for k, v in numDict.items()}
for number in numbers:
print(letterDict[number], end="")
while(True):
choice = input("Letters to T9 (L)? Or Reverse (R)?\t")
if choice == 'L':
lettersToT9()
break
elif choice == 'R':
t9ToLetters()
break
else:
print("Invalid Choice")