|
1 | | -# LANGUAGE: PYTHON |
2 | | -# FEATURE PHONE KEY PRESSES |
3 | | - |
4 | | - |
5 | | -# This is a feature phone keypad: |
6 | | - |
7 | | -# ------- ------- ------- |
8 | | -# | | | ABC | | DEF | |
9 | | -# | 1 | | 2 | | 3 | |
10 | | -# ------- ------- ------- |
11 | | -# ------- ------- ------- |
12 | | -# | GHI | | JKL | | MNO | |
13 | | -# | 4 | | 5 | | 6 | |
14 | | -# ------- ------- ------- |
15 | | -# ------- ------- ------- |
16 | | -# |PQRS | | TUV | | WXYZ| |
17 | | -# | 7 | | 8 | | 9 | |
18 | | -# ------- ------- ------- |
19 | | -# ------- ------- ------- |
20 | | -# | | | | | | |
21 | | -# | * | | 0 | | # | |
22 | | -# ------- ------- ------- |
23 | | - |
24 | | - |
25 | | -# Before predictive text entry systems like T9, you had to press a button |
26 | | -# repeatedly to cycle through the possible values until you reached |
27 | | -# the one you wanted. |
28 | | - |
29 | | -# For example, to type "V8" you would press the 8 key three times and then |
30 | | -# again four times (pressing the 8 key cycles through T->U->V->8), |
31 | | -# giving us a total of seven key presses. |
32 | | - |
33 | | -# Note: the 0 key handles spaces and outputs 0 when tapped twice. |
34 | | - |
35 | | -# Write a function that can calculate the amount of button presses required for any phrase. |
36 | | -# Except for spaces, punctuation can be ignored. |
37 | | -# Your function should accept both uppercase and lowercase letters and treat them the same. |
38 | | - |
39 | | -# Examples: |
40 | | -# presses('V8') # 7 |
41 | | -# presses('LOL') # 9 |
42 | | -# presses('How R u 2day') # 23 |
43 | | - |
44 | | -# Bonus: Try to avoid hard-coding the number of button presses for each letter! |
45 | | -# Resource: http://www.learnpython.org/en/Dictionaries |
46 | | -# Use python Dictionaries in this exercise |
47 | | - |
48 | | - |
49 | | - |
50 | 1 | def presses(str): |
51 | 2 | # Your Code Here! |
52 | 3 |
|
|
0 commit comments