/
numerickeys1.py
46 lines (39 loc) · 939 Bytes
/
numerickeys1.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
"""
numerickeys1.py
The keys of this dictionary are consecutive integers.
A list would be simpler than a dictionary in this case.
"""
import sys
words = {
1: "one",
2: "two",
3: "three",
4: "four",
5: "five",
6: "six",
7: "seven",
8: "eight",
9: "nine",
10: "ten"
}
while True:
try:
s = input("Please type an integer from 1 to 10 inclusive: ")
except EOFError:
sys.exit(0)
try:
n = int(s)
except ValueError:
print(f'Sorry, "{s}" is not an integer.')
print("Try again.")
print()
continue #Go back up to the word "while".
try:
word = words[n]
except KeyError:
print(f"Sorry, {s} is not an integer in the range 1 to 10 inclusive.")
print("Try again.")
print()
continue #Go back up to the word "while".
print(f'The word for {n} is "{word}".')
print()