I am a beginner programmer in python and I need assistance with some code. Attached is the code I have been working on. The purpose is to take a dollar amount like 305.67 and convert the number to a text phrase like "Three Hundred Five Dollars and Sixty Seven Cents". So far I have gotten most of the code to break it into text, but I have still issues with the numbers 11-19 which is a special case. I need help figuring out how the program can decide where to apply 11-19 properly and also when to delete the "ZERO" string when it is not needed. If you run the program, you will see what I mean. The loop below in the main function would run the loop given the amount you wish depending on the function. Also, there is a function called "getDollarFormatText" which will take the numerical version of money such as 305.67 or 45.13 and give you the text format of it. The issue I run into is how do i get the program to ignore the decimal and then to convert everything to the left and right of the decimal appropriately. This is a loaded issue, and I will appreciate this thoroughly. Essentially the issue is easy to fix, but I have no idea how to tackle it. The code starts with a function that tackles two digit numbers (i have already tackled the function that separates by only single digit numbers).
def getWordForTwoDigits(amount):
#This value uses integer division to get the number of tens within a number.
tensAmount = int(amount) / 10
#This variable uses the first function above to find the equivalent single number within the number given using modulo. (Zero through 9)
singlesWord = getWordForDigit(int(amount)%10)
#For this decision structure, the structure is set to figuring out the number of tens within a number and appropriately naming it after its correct name (ten, twenty, etc.)
if tensAmount == 1:
wordTen = "TEN"
else:
if tensAmount == 2:
wordTen = "TWENTY"
else:
if tensAmount == 3:
wordTen = "THIRTY"
else:
if tensAmount == 4:
wordTen = "FORTY"
else:
if tensAmount == 5:
wordTen = "FIFTY"
else:
if tensAmount == 6:
wordTen = "SIXTY"
else:
if tensAmount == 7:
wordTen = "SEVENTY"
else:
if tensAmount == 8:
wordTen = "EIGHTY"
else:
if tensAmount == 9:
wordTen = "NINETY"
return "%s-%s"%(wordTen, singlesWord)
########################################
def getWordForThreeDigits(dolamount):
hundredAmount = int(dolamount) / 100
twoDigits = getWordForTwoDigits(int(dolamount) % 100)
if hundredAmount == 0:
return twoDigits
else:
if hundredAmount == 1:
wordHun = "ONE HUNDRED"
else:
if hundredAmount == 2:
wordHun = "TWO HUNDRED"
else:
if hundredAmount == 3:
wordHun = "THREE HUNDRED"
else:
if hundredAmount == 4:
wordHun = "FOUR HUNDRED"
else:
if hundredAmount == 5:
wordHun = "FIVE HUNDRED"
else:
if hundredAmount == 6:
wordHun = "SIX HUNDRED"
else:
if hundredAmount == 7:
wordHun = "SEVEN HUNDRED"
else:
if hundredAmount == 8:
wordHun = "EIGHT HUNDRED"
else:
if hundredAmount == 9:
wordHun = "NINE HUNDRED"
return "%s %s"%(wordHun, twoDigits)
####################################
def getDollarFormatText(dollarAndCents):
#how would you separate 190.67 (example) to 190 and 67 and and give the text form for eacn