Hi all,
I am a beginning Python programmer working my way through Wesley Chun's Core Python Programming. One of the exercises is to write a program that converts a numerical input, e.g. 654, into text.
When I try to run this I get a syntax error on line 29.
For the life of me, I can't see what could be wrong with this. I have run equivalent commands in the interactive interpreter and everything worked fine. I would greatly appreciate any help you could give me.
Thanks,
Evan
(Here is the program:)
I am a beginning Python programmer working my way through Wesley Chun's Core Python Programming. One of the exercises is to write a program that converts a numerical input, e.g. 654, into text.
When I try to run this I get a syntax error on line 29.
Code:
numString = str(letterList[0])
Thanks,
Evan
(Here is the program:)
Code:
#!/usr/bin/env python
"Generates a textual representation of a numerical input."
numberList = ['zero', 'one', 'two', 'three', 'four',
'five', 'six', 'seven', 'eight', 'nine']
numberListTeens = ['ten', 'eleven', 'twelve', 'thirteen',
'fourteen', 'fifteen', 'sixteen', 'seventeen',
'eighteen', 'nineteen', 'twenty']
numberListTens = ['zero', 'ten', 'twenty', 'thirty', 'fourty',
'fifty', 'sixty', 'seventy', 'eighty',
'ninety', 'one-hundred']
numberListHundreds = ['zero', 'one-hundred-and', 'two-hundred-and',
'three-hundred-and', 'four-hundred-and',
'five-hundred-and', 'six-hundred-and'
'seven-hundred-and', 'eight-hundred-and'
'nine-hundred-and']
inputList = []
letterList = []
def NumberPrinterProperUsage(numString):
for char in numString:
inputList.append(int(char))
if len(inputList) == 1:
letterList.append(numberList(inputList[0])
numString = str(letterList[0])
print numString
elif len(inputList) == 2:
if inputList[0] = 1:
letterList.append(numberListTeens(inputList[1])
numString = str(letterList[0])
print numString
else:
letterList.append(numberListTens(inputList[0])
letterList.append(numberList(inputList[1])
numString = '-'.join(letterList)
print numString
elif len(inputList) == 3:
letterList.append(numberListHundreds(inputList[0])
letterList.append(numberListTens(inputList[1])
letterList.append(numberList(inputList[2])
numString = '-'.join(letterList)
print numString
else:
print "Please enter a number between 0 and 999. Exiting..."
def Menu():
stringInput = raw_input("Please enter a number. ")
NumberPrinterProperUsage(stringInput)
if __name__ == '__main__':
Menu()
Comment