1
+ #Matt Nichols
2
+ #HB2 Lab03
3
+
4
+ #Version 1
5
+
6
+ #Dictionaries for future key[input] to output
7
+ ones_place = {
8
+ 0 : 'zero' ,
9
+ 1 : 'one' ,
10
+ 2 : 'two' ,
11
+ 3 : 'three' ,
12
+ 4 : 'four' ,
13
+ 5 : 'five' ,
14
+ 6 : 'six' ,
15
+ 7 : 'seven' ,
16
+ 8 : 'eight' ,
17
+ 9 : 'nine' ,
18
+ }
19
+ complex_place = {
20
+ 10 : 'ten' ,
21
+ 11 : 'eleven' ,
22
+ 12 : 'twelve' ,
23
+ 13 : 'thirteen' ,
24
+ 14 : 'fourteen' ,
25
+ 15 : 'fifteen' ,
26
+ 16 : 'sixteen' ,
27
+ 17 : 'seventeen' ,
28
+ 18 : 'eighteen' ,
29
+ 19 : 'nineteen'
30
+ }
31
+ tens_place = {
32
+ 2 : 'twenty' ,
33
+ 3 : 'thirty' ,
34
+ 4 : 'forty' ,
35
+ 5 : 'fifty' ,
36
+ 6 : 'sixty' ,
37
+ 7 : 'seventy' ,
38
+ 8 : 'eighty' ,
39
+ 9 : 'ninty'
40
+ }
41
+
42
+ #Function for when you need to pull from two keys with one input
43
+ def twenty_to_ninty_nine (nums ):
44
+ tens = nums // 10
45
+ ones = nums % 10
46
+ if ones == 0 :
47
+ return tens_place [tens ]
48
+ return '{0}-{1}' .format (tens_place [tens ], ones_place [ones ])
49
+
50
+ #Function for putting the everything together
51
+ def zero_to_ninty_nine (nums ):
52
+ if nums < 10 :
53
+ return ones_place [nums ]
54
+ elif nums < 20 :
55
+ return complex_place [nums ]
56
+ return twenty_to_ninty_nine (nums )
57
+
58
+ #Version2
59
+
60
+ #Function for finding/pulling more keys with one input
61
+ def hundreds (nums ):
62
+ hundreds = nums // 100
63
+ tens = nums % 100
64
+ ones = nums % 10
65
+ if tens == 0 :
66
+ return f'{ ones_place [hundreds ]} -hundred'
67
+ if tens < 10 :
68
+ return f'{ ones_place [hundreds ]} -hundred-{ ones_place [ones ]} '
69
+ if tens < 20 :
70
+ return f'{ ones_place [hundreds ]} -hundred-{ complex_place [tens ]} '
71
+ return f'{ ones_place [hundreds ]} -hundred-{ twenty_to_ninty_nine (tens )} '
72
+
73
+ #Putting it all together
74
+ def numbers_zero_to_hundreds (nums ):
75
+ if nums < 10 :
76
+ return ones_place [nums ]
77
+ if nums < 20 :
78
+ return complex_place [nums ]
79
+ if nums < 100 :
80
+ return twenty_to_ninty_nine (nums )
81
+ return hundreds (nums )
82
+
83
+
84
+ while True :
85
+ user_input = input ("Enter a number between 0-999 OR type 'done' to exit\n " )
86
+ #Ending program
87
+ if user_input == 'done' :
88
+ result = "Goodbye"
89
+ print (result )
90
+ break
91
+ #For users invalid input
92
+ try :
93
+ number_to_string = numbers_zero_to_hundreds (int (user_input ))
94
+ print (number_to_string )
95
+ except :
96
+ print (f"You entered - { user_input } .\n Make sure you have no spaces, numbers don't exceed 999, and no negatives " )
97
+
98
+
0 commit comments