so I was writing a pig latin translator program, and I ran into trouble, when trying to append the first letter of each word to the end of the word. I debugged the code, and I found that the line "list=listEnd.append(firstLetter)" (in bold below) was evaluating to None, which caused the next line, "list=list.append('ay')" to crash. Can anybody tell me why this is happening?
The error message is: Traceback (most recent call last): File "C:\Python34\pigLatinTranslator.py", line 33, in list=listEnd.append(firstLetter).append('ay') AttributeError: 'NoneType' object has no attribute 'append'
Thanks!!
def getSentence():
print('Enter a sentence you would like to translate to pig Latin(letters and spaces only)')
sentence=input()
return sentence
def isStartsWithConsonant(word):
for i in 'bcdfghjklmnpqrstvwxyz':
if word.startswith(i):
return True
while True:
sentence=getSentence()
#if isValidSentence(sentence):
sentenceList=sentence.split()
listLists=[]
for w in sentenceList[:]:
wList=[]
for l in w:
wList.append(l)
listLists.append(wList)
for list in listLists:
if isStartsWithConsonant(list[0]):
listEnd=list[1:]
firstLetter=list[0]
list=listEnd.append(firstLetter).append('ay')
else:
listEnd=list[1:]
firstLetter=list[0]
list=listEnd.append(firstLetter)
list.append('way')
translatedSentence=''
for list in listLists:
for l in list:
translatedSentence.append(l)
translatedSentence.append(' ')
print('Your sentence translated to pig Latin is:'+translatedSentence)
print('Do you want to translate another sentence?')
if not input().startswith(y):
break