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