Here is an example of how your program should behave/work (put in red for clarification):
Welcome to the Random Poems of the Day!
How many poems would you like me to generate for you? 3
Here are your 3 poems:
Paris Hilton amazingly eats mice in Duckett House every Sunday afternoon
The cat never runs on the sofa early in the morning
Mrs Christ sometimes runs on the sofa at night
The the poems are centered, with the longest poem starting at the leftmost column. In other words, the longest poem does not have any spaces in front of its first word.
You will need to use the max() function, which returns the maximum of a list of numbers.
list = [ 1, 10, 3, 4, -10, 300, 2 ]
print( max( list ) )
I have a code that generates the random poems, but I am having two problems. 1) I can't seem to get the program to read "Here are your 3 poems" if the user types in 3, I can only get "Here are your poems". 2) I'm not sure how to use this max () function to center the poems, the longest starting at the leftmost column. May I please have help with this? Thank you! Here is my code so far:
import random
def main():
#create a list of people
people=["Lil Wayne", "Nicole Richie", "The garbage man", "The Vice-Presiden\
t"]
#creaate a list of verbs
verb=["twirls", "shakes", "dances", "yodels", "jumps", "spits"]
#create a list of adverbs
adverb=["all the time", "once every two weeks", "ridiculously", "strongly",\
"frequently"]
#create a list of locations
location=["on the hood of the car","behind the stairs", "in front of the pr\
incipal"]
#create a list of times
time_=["at 1 o'clock in the morning", "at sunrise", "at dinner", "at 8pm", \
"during brunch"]
#figure out how many people, verbs, adverbs, locations, and times are in
#people, verb, adverb, location, and time, respectively.
poems=[' '.join(random.choice(a) for a in (people, verb, adverb, location, \
time_))
for count in range(int(input("How many poems would you like me t\
o generate for you?")))]
#greeting
print(""" Welcome to Random Poems of the Day!
Here are your poems""")
print('.\n'.join(poems)+'.')
main()


Sign In
Create Account

This topic is locked
Back to top









