My function recursively calls itself until it decodes every numbers. rec_ntw
face_value_count -> (Incremental variable) denotes ones, tens, hundreds and thousands face_value -> (Dictionary) denotes the dictionary containing corresponding the word value for numbers.
result -> (String) Contains final result to return.
teen -> (Integer) to decode the teen numbers from eleven to ninteen
number % 10 to get the last element
number // 10 to remove the last element and pass it on to recursive the function.
def rec_ntw(number, face_value_count=0):
result = ""
teen = 0
if number <= 0:
if face_value_count == 0:
result = "Zero"
print (result)
#return result
else:
if face_value_count == 0:
result = (singleton[int(number % 10)])
teen = number % 10
elif face_value_count == 1:
if number % 10 == 1:
result = (face_value[1][1][int(teen)]) + " "
else:
result = (face_value[int(face_value_count)][int(number % 10)]) + " " + result
teen = 0
elif face_value_count == 2:
if number % 10 != 0:
result = (singleton[int(number % 10)] + " " + str(face_value[int(face_value_count)]) + " ") + result
else:
result = (singleton[int(number % 10)] + " " + str(face_value[int(face_value_count)]) + " ") + result
face_value_count += 1
rec_ntw(number // 10, face_value_count)
Please review my code and lemme know how to write effectively.
face_value
would be a great addition to this post. \$\endgroup\$singleton
? \$\endgroup\$