Hello. I am new to python, and this is my first app. Instead of calling paragraphbuilder() and sentencetype1(), the program flow just passes through. Thanks in advance!
""" Generate sentence type one """
def sentencetype1():
rand = random.randint(1,2)
if rand == 1:
text = "I want to "
if rand == 2:
text = "I "
verb_choices = random.sample(Verb, 12 + themevector1)
text = text + random.choice(verb_choices)
text + " the "
if random.randint(1,2) == 1:
adjective_choices = random.sample(Adjective, 12 + themevector1)
text + random.choice(adjective_choices)
noun_choices = random.sample(Noun, 12 + themevector1)
text + random.choice(noun_choices)
else:
noun_choices = random.sample(Noun, 12 + themevector1)
text + random.choice(noun_choices)
return Adjective, Noun, Verb, text
""" Paragraph builder """
def paragraphbuilder():
numbersentences = random.randint(1,50)
x = 1
while x < numbersentences:
sentencetype = 1
if sentencetype == 1:
sentencetype1()
x += 1
return text
""" Generate story """
y = 1
while y < numberparas:
paragraphbuilder()
y += 1
Right now you’re discarding the return value of paragraphbuilder(). Do you mean to do something with it, e.g. print it? I don’t see any print statements or other forms of output.
Right. However the text that it builds isn’t being printed anywhere.
Looking a bit closer at the inside of those functions, it seems you have some other issues with return values. paragraphbuilder ends with return text, but you don’t assign to text anywhere in that function. It also calls sentencetype1, but doesn’t use the return value. Inside sentencetype1, you have return Adjective, Noun, Verb, text, where Adjective, Noun, and Verb appear to be global constants and only text seems to be needed by the caller.
You probably want to make sentencetype1 just return text, and rewrite paragraphbuilder to something like
def paragraphbuilder():
sentences = []
for _ in range(random.randint(1,50)):
sentences.append(sentencetype1())
return ". ".join(sentences)
Be sure to print the return value of paragraphbuilder inside the main loop.
If you just call paragraphbuilder(), Python will happily construct the string then throw it away. In order to see the string, you need to capture the return value and do something with it, like call print with it, write it to a file, etc.