Skip to content

Commit 7c2520a

Browse files
Recursion- mobile keypad possible combination
1 parent 9253108 commit 7c2520a

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

keypad_combi.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
def get_characters(num):
2+
if num == 2:
3+
return "abc"
4+
elif num == 3:
5+
return "def"
6+
elif num == 4:
7+
return "ghi"
8+
elif num == 5:
9+
return "jkl"
10+
elif num == 6:
11+
return "mno"
12+
elif num == 7:
13+
return "pqrs"
14+
elif num == 8:
15+
return "tuv"
16+
elif num == 9:
17+
return "wxyz"
18+
else:
19+
return ""
20+
21+
def keypad(num):
22+
if num <= 1:
23+
return ""
24+
elif 2 <= num <= 9:
25+
return get_characters(num)
26+
out = list()
27+
last_digit = num%10
28+
small = keypad(num//10)
29+
keypad_string = get_characters(last_digit)
30+
for char in keypad_string:
31+
for item in small:
32+
new_item = item+char
33+
out.append(new_item)
34+
return out
35+
36+
print(keypad(232))

0 commit comments

Comments
 (0)