-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEngSpell.py
52 lines (46 loc) · 1.12 KB
/
EngSpell.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
47
48
49
50
51
#pro gram to spell out number in English
#the user enters a number and its spelt out with its suffix in English
def asknum():
global num
while True:
try:
num=input("Enter a number:")
except:
print "Thats not a number!! :("
continue
else:
break
def spell_out(num):
if num==1:
str_num=str(num)
store_num=str_num+"st"
print "It's spelt out as: ",store_num
elif num==2:
str_num=str(num)
store_num=str_num+"nd"
print"It's spelt out as: ",store_num
elif num==3:
str_num=str(num)
store_num=str_num+"rd"
print"It's spelt out as: ",store_num
elif num>=4 and num<21:
str_num=str(num)
store_num=str_num+"th"
print"It's spelt out as: ",store_num
elif num>20:
str_num=str(num)
len_num=len(str_num)
if int(str_num[len_num-1])==1:
store_num=str_num+"st"
print "It's spelt out as: ",store_num
elif int(str_num[len_num-1])==2:
store_num=str_num+"nd"
print "It's spelt out as: ",store_num
elif int(str_num[len_num-1])==3:
store_num=str_num+"rd"
print "It's spelt out as: ",store_num
else:
store_num=str_num+"th"
print "It's spelt out as: ",store_num
asknum()
spell_out(num)