I've been trying to program a Mad-Libs Simulator in Python 3.3.3 and I have been receiving the error:
Traceback (most recent call last):
File "/Users/RuzHayes_Laptop/Desktop/Programming:Design/Programs/Python Mad Libs Program 000.py", line 80, in <module>
templates=[("The"+" "+adj+" "+n+" "+v+" "+adv+pun),(adj+" "+pluralize(n)+' '+(v[:len(v)-1])+" "+adv+pun)]
TypeError: Can't convert 'NoneType' object to str implicitly
In the following code:
print("Welcome!")
print("When you would like to try out ")
print("Python Mad Libs Program, Prototype000,")
begin=input("press the enter/return key.")
print()
print()
print("Initializing befuddlement...")
print()
import random
sentenceCap=35
sentenceBottom=25
numOfSentences=random.randint(sentenceBottom,sentenceCap)
caps={"a":"A","b":"B","c":"C","d":"D",'e':'E','f':'F','g':'G','h':'H','i':'I','j':'J','k':'K','l':'L','m':'M','n':'N','o':'O','p':'P','q':'Q','r':'R','s':'S','t':'T','u':'U','v':'V','w':'W','x':'X','y':'Y','z':'Z'}
tempstore=[" "]*numOfSentences
irregplrls={'child':'children','ox':'oxen','moose':'moose'}
def testforoo(x):
for j in range(0,len(x)):
if j+1<=len(x) and x[j:j+1]=='oo'.lower():
return True
return False
def pluralize(x):
l=len(x)
for i in irregplrls:
if i == x:
return irregplrls[x]
if x[l-1]=="y":
return x[:l-1]+"ies"
elif x[l-1]=="s" and x[l-2]=="u":
return x[:l-2]+"i"
elif x[l-1] in ('s','x'):
return x+"es"
elif x[-2:] in ('ch','sh'):
return x+"es"
elif 'f'==x[l-1] or x[l-2]:
if 'f'==x[l-1]:
return x[:l-1] + 'ves'
elif 'f'==x[l-2]:
return x[:l-2]+"ves"
elif testforoo(x)!=False:
return x[:testforoo(x)-2]+'ee'+x[testforoo(x):]
else:
return x+'s'
print()
print("Retrieving craploads of words...")
print()
verb=["moves","jumps", "hides","sniffs","gazes","sneezes","calls"]
noun=["rabbit","dog","cat","otter","seal","elephant","fox",'baby','moose','octopus']
adjec=["happy","angry","cute","enormous","elegant","annoying"]
adver=["merrily","frustratedly","incoherently","morosely","peppily",'exuberantly']
endpunct=[".","!"]
print()
print("Simulating human grammar-speak...")
print()
print()
for i000 in range(0,numOfSentences):
v=random.choice(verb)
n=random.choice(noun)
adj=random.choice(adjec)
adv=random.choice(adver)
pun=random.choice(endpunct)
askinput=random.randint(0,round(numOfSentences/5))
whichinput=random.randint(0,3)
if askinput==0:
if whichinput==0:
n=input("Please input a noun. ")
elif whichinput==1:
v=input("Please input a verb. ")
elif whichinput==2:
adj=input("Please input an adjective. ")
elif whichinput==3:
adv=input("Please input an adverb. ")
templates=[("The"+" "+adj+" "+n+" "+v+" "+adv+pun),(adj+" "+pluralize(n)+' '+(v[:len(v)-1])+" "+adv+pun)]
final=templates[random.randint(0,len(templates)-1)]
if final[:1]==final[:1].lower():
final=caps[final[:1]]+final[1:]
tempstore[i000]=final
print()
print()
print("Producing proof of illiteracy...")
print()
print()
for i001 in range(0,len(tempstore)):
sent=tempstore[i001]
print(sent)
I am very confused and I need help. I have now found the problem to be in the end of the pluralize definition, but otherwise I am very confused. The program worked until I changed pluralize to account for certain nouns not being correctly pluralized.
I will appreciate any help you can give me. I have only been programming for about a month now and this is the hardest program I have ever attempted.
Thank you and Merry Christmas! That is, of course, if you celebrate Christmas.