Python Lesson 14 Exercises: Using Dictionaries
In the following exercise, pay attention to your user interface, be certain to test the programs rigorously, and make the programs as "fool proof" as possible. Save each program as pa14-1.py, pa14-2.py and so forth.
Exercise 1:
Write a program that will convert a word or text string into "phonetic alphabet". The phonetic alphabet is used when spelling words out. The list below is the standard NATO phonetic alphabet for English. Any numbers should be printed out as words.
A = Alpha
B = Bravo
C = Charlie
D = Delta
E = Echo
F = Foxtrot
|
G = Golf
H = Hotel
I = India
J = Juliet
K = Kilo
L = Lima
|
M = Mike
N = November
O = Oscar
P = Papa
Q = Quebec
R = Romeo
|
S = Sierra
T = Tango
U = Uniform
V = Victor
W = Whiskey
X = Xray
|
Y = Yankee
Z = Zulu
|
Example
PYTHON = Papa Yankee Tango Hotel Oscar November
Exercise 2:
Write a program that will print as many numbers in the fibonacci sequence as the user requests. The fibonacci sequence starts with the numbers 0 and 1, then all subsequent values are created by adding the two previous numbers together. So if the user asked for the first 11 numbers in the sequence, the program should print the following:
0 1 1 2 3 5 8 13 21 34 55
Exercise 3:
Write a program that can convert between Morse Code and plain text. The program should read information from a text file, ask the user whether it contains Morse Code or Regular Text, then covert the text into the opposite format. The user should be given an option to either view the output or save it to a new file.
A .-
B -...
C -.-.
D -..
E .
F ..-.
|
G --.
H ....
I ..
J .---
K -.-
L .-..
|
M --
N -.
O ---
P .--.
Q --.-
R .-.
|
S ...
T -
U ..-
V ...-
W .--
X -..-
|
Y -.--
Z --..
|
Restricted access |