-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathletters.py
More file actions
37 lines (33 loc) · 982 Bytes
/
letters.py
File metadata and controls
37 lines (33 loc) · 982 Bytes
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
t = 'abcdefghijklmnopqrstuvwxyz'
def ordinal(letter):
index = t.index(letter) + 1
if index in [11, 12, 13]:
return f"{index}th"
if index % 10 == 1:
return f"{index}st"
if index % 10 == 2:
return f"{index}nd"
if index % 10 == 3:
return f"{index}rd"
return f"{index}th"
try:
while True:
s = input('Enter a letter: ')
if s in ('stop', '^C', '^D'):
print('Goodbye.')
break
if s.isspace() or not s:
print('Please enter a single letter.')
continue
if s.isalpha() and len(s) != 1:
print('Please enter a single letter.')
continue
if not s.isalpha():
print('Please enter a letter from the English alphabet.')
continue
s = s.lower()
print(f"'{s}' is the {ordinal(s)} letter of the alphabet.")
except KeyboardInterrupt as e:
print(e)
except EOFError:
print("Goodbye.")