Skip to content

Commit 8cfa450

Browse files
committed
finished
1 parent ec8c2ab commit 8cfa450

File tree

1 file changed

+28
-10
lines changed

1 file changed

+28
-10
lines changed

code/Andy/python/lab03_number_to_phrases_v2.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#version 2
2+
3+
4+
25
low_numbers = {
36
0: "zero",
47
1: "one",
@@ -56,23 +59,38 @@ def convert_number(number):
5659
if number < 20:
5760
return low_numbers[number]
5861

59-
elif number < 100:
62+
# elif number < 100:
6063

61-
tens_digit = number // 10
62-
# print('10s digit: ', tens_digit)
63-
ones_digit = number % 10 #takes whatever number and divides that by 10 and then gives the remainder
64-
# print('1s digit: ', ones_digit)
65-
# return f"{ten[tens_digit]} - {low_numbers[ones_digit]}"
66-
tens_word = ten[tens_digit]
67-
ones_word = low_numbers[ones_digit]
68-
return f'{tens_word + " " + ones_word}'
64+
# tens_digit = number // 10
65+
# # print('10s digit: ', tens_digit)
66+
# ones_digit = number % 10 #takes whatever number and divides that by 10 and then gives the remainder
67+
# # print('1s digit: ', ones_digit)
68+
# # return f"{ten[tens_digit]} - {low_numbers[ones_digit]}"
69+
# tens_word = ten[tens_digit]
70+
# ones_word = low_numbers[ones_digit]
71+
# # print('ones word: ', ones_word)
72+
# # print('type of ones word: ', type(ones_word))
6973

74+
# # print(ones_word[0])
75+
# # print(ones_word[1])
76+
# # print(ones_word[2])
77+
# # print(ones_word[3])
78+
79+
# return f'{tens_word + " " + low_numbers[ones_digit]}'
80+
81+
elif number < 100:
82+
tens_digit = number//10
83+
ones_digit = number%10
84+
last_one = int(str(number)[-1:]) #calling the the last number that is being inputed
85+
if last_one == 0: # its saying that its only calling the last number if it is 0
86+
return f'{ten[tens_digit]}'
7087

7188
elif number < 999:
7289
hundreds_digit = number // 100 #floor divide regular division with no remainder
7390
hundreds_word = hundreds[hundreds_digit]
7491
last_two = int(str(number)[-2:]) #python get last two digits in number stack exchange
7592
last_one = int(str(number)[-1:])
93+
7694

7795

7896

@@ -85,7 +103,7 @@ def convert_number(number):
85103
tens_word = ten[new_tens]
86104
ones_word = low_numbers[ones_digit]
87105
if last_one == 0:
88-
return f'{hundreds_word + " " + tens_word}' #placing this here to be able to get the numbers with 0 at the end, from having it say number then adding zero also placement beacause it needs to run all of that to be able to distinguish when it needs to use it
106+
return f'{hundreds_word + " " + ten[new_tens]}' #placing this here to be able to get the numbers with 0 at the end, from having it say number then adding zero also placement beacause it needs to run all of that to be able to distinguish when it needs to use it
89107

90108
return f'{hundreds_word + " " + tens_word + " " + ones_word}'
91109

0 commit comments

Comments
 (0)