Skip to content

Commit 94e3923

Browse files
committed
exercise five
1 parent 25093b5 commit 94e3923

1 file changed

Lines changed: 57 additions & 7 deletions

File tree

readme.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
** Question: 1 **
1+
### Question: 1
22

33
Write a program that accepts a comma separated sequence of words as input and prints the words in a comma-separated sequence after sorting them alphabetically.
44
Suppose the following input is supplied to the program:
@@ -12,7 +12,7 @@ Use a sorting method
1212

1313

1414

15-
** Question: 2 **
15+
### Question: 2
1616

1717
Write a program that accepts sequence of lines as input and prints the lines after making all characters in the sentence capitalized.
1818
Suppose the following input is supplied to the program:
@@ -28,7 +28,7 @@ Use list and append
2828

2929

3030

31-
** Question: 3 **
31+
### Question: 3
3232

3333
Write a program which accepts a sequence of comma separated 4 digit binary numbers as its input and then check whether they are divisible by 5 or not. The numbers that are divisible by 5 are to be printed in a comma separated sequence.
3434
Example:
@@ -42,7 +42,7 @@ In case of input data being supplied to the question, it should be assumed to be
4242
Use list and .join
4343

4444

45-
** Question: 4 **
45+
### Question: 4
4646

4747
Write a password generator in Python.
4848
Be creative with how you generate passwords - strong passwords have a mix of lowercase letters, uppercase letters, numbers, and symbols.
@@ -53,7 +53,10 @@ Hint:
5353
use Python’s random module,
5454

5555
```
56-
This is your first exposure to using Python code that somebody else wrote. In Python, these formally-distributed code packages are called modules. The thing we want from a module in this exercise is the ability to generate random numbers. This comes from the random module.
56+
This is your first exposure to using Python code that somebody else wrote.
57+
In Python, these formally-distributed code packages are called modules.
58+
The thing we want from a module in this exercise is the ability to generate random numbers.
59+
This comes from the random module.
5760
5861
To use a module, at the top of your file, type
5962
```
@@ -62,7 +65,8 @@ To use a module, at the top of your file, type
6265
import random
6366
```
6467
```
65-
This means you are allowing your Python program to use a module called random in the rest of your code.
68+
This means you are allowing your Python program to use a module called random in
69+
the rest of your code.
6670
6771
To use it (and generate a random integer), now type:
6872
```
@@ -76,4 +80,50 @@ Once you run this program, the variable a will have a random integer that the co
7680
Bonus:
7781
Ask the user how strong they want their password to be. For weak passwords, pick a word or two from a list.
7882

79-
Happy coding!
83+
Happy coding!
84+
85+
86+
### Question 5
87+
88+
This is a feature phone keypad:
89+
90+
------- ------- -------
91+
| | | ABC | | DEF |
92+
| 1 | | 2 | | 3 |
93+
------- ------- -------
94+
------- ------- -------
95+
| GHI | | JKL | | MNO |
96+
| 4 | | 5 | | 6 |
97+
------- ------- -------
98+
------- ------- -------
99+
|PQRS | | TUV | | WXYZ|
100+
| 7 | | 8 | | 9 |
101+
------- ------- -------
102+
------- ------- -------
103+
| | | | | |
104+
| * | | 0 | | # |
105+
------- ------- -------
106+
107+
108+
Before predictive text entry systems like T9, you had to press a button
109+
repeatedly to cycle through the possible values until you reached
110+
the one you wanted.
111+
112+
For example, to type "V8" you would press the 8 key three times and then
113+
again four times (pressing the 8 key cycles through T->U->V->8),
114+
giving us a total of seven key presses.
115+
116+
Note: the 0 key handles spaces and outputs 0 when tapped twice.
117+
118+
Write a function that can calculate the amount of button presses required for any phrase.
119+
Except for spaces, punctuation can be ignored.
120+
Your function should accept both uppercase and lowercase letters and treat them the same.
121+
122+
Examples:
123+
presses('V8') # 7
124+
presses('LOL') # 9
125+
presses('How R u 2day') # 23
126+
127+
Bonus: Try to avoid hard-coding the number of button presses for each letter!
128+
Resource:
129+
Use python [Dictionaries](http://www.learnpython.org/en/Dictionaries) in this exercise

0 commit comments

Comments
 (0)