Jump to content

Python 3.2.2 Problem

- - - - -

  • This topic is locked This topic is locked
3 replies to this topic

#1
computerchip

computerchip

    Newbie

  • Members
  • Pip
  • 1 posts
Hello, I am a new CSC 111 student. I seem to be having trouble on this problem where I am supposed to create a code that generates an interactive list of poems. Here is the problem, followed by my questions, followed by the code I have up to this point. May I please have help with this? I would really appreciate it. Thank you!


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()


#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
print "Welcome to Random Poems of the Day! Here are your", number_of_poems, "poems"

I'll get back to you on the centering thing.
sudo rm -rf /

#3
velmasemson

velmasemson

    Newbie

  • Members
  • Pip
  • 1 posts
hi computerchip, I find and use this Pyhton 3.2.2 no problem.

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Please don't resurrect old threads, as the people involved are probably long gone and it pushes newer active threads down in the list. Thread closed.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users