Python One day practice----Poetry Generator

Source: Internet
Author: User

Requirements

Write a program that can automatically generate small poems.

The format is as follows


Source Code


Import Randomimport sysarticles = ["The", "a", "another", "her", "he"]subjects = ["Cat", "dog", "horse", "Man", "Woman",  "Boy", "girl"]verbs = ["sang", "ran", "jumped", "said", "fought", "swam", "saw",          "heard", "Felt", "slept", "hopped", "hoped", "cried",          "laughed", "walked"]adverbs = ["loudly", "Q Uietly "," quickly "," slowly "," well "," badly ",           " rudely "," politely "]lines = 5if le N (sys.argv) > 1:    try:        temp = int (sys.argv[1])         if 1 & lt;= temp <= 10:            lines = temp        else:    &N Bsp       Print ("Lines must be 1-10 inclusive")     except valueerror:        Prin T ("usage:badpoetry.py [lines]") while lines:    Article = Random.choice (articles)     subject = random . Choice (subjects) &NBSp   verb = random.choice (verbs)     If Random.randint (0, 1) = = 0:        print (article, Su Bject, verb)     else:        adverb = Random.choice (adverbs)         Prin T (article, subject, verb, adverb)     lines-= 1





If you have any questions, welcome to my public question ~


Python One day practice----Poetry Generator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.