Python一日一练02----诗词生成器
来源:互联网 发布:js隐藏select标签 编辑:程序博客网 时间:2024/05/01 17:58
要求
编写一段程序,可以自动生成小诗。
格式如下
源码
import randomimport sysarticles = ["the", "a", "another", "her", "his"]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", "quietly", "quickly", "slowly", "well", "badly", "rudely", "politely"]lines = 5if len(sys.argv) > 1: try: temp = int(sys.argv[1]) if 1 <= temp <= 10: lines = temp else: print("lines must be 1-10 inclusive") except ValueError: print("usage: badpoetry.py [lines]")while lines: article = random.choice(articles) subject = random.choice(subjects) verb = random.choice(verbs) if random.randint(0, 1) == 0: print(article, subject, verb) else: adverb = random.choice(adverbs) print(article, subject, verb, adverb) lines -= 1
欢迎收听我的微信公众号
1 0
- Python一日一练02----诗词生成器
- 设计模式一日一练:生成器模式(Builder)
- Python一日一练100----消息服务器
- Python一日一练01----字符输出
- Python一日一练03----输出网页
- Python一日一练07----冒泡排序
- Python一日一练08----鸡尾酒排序
- Python一日一练09----奇偶排序
- Python一日一练10----快速排序
- Python一日一练11----选择排序
- Python一日一练12----堆排序
- Python一日一练13----插入排序
- Python一日一练14----希尔排序
- Python一日一练15----归并排序
- Python一日一练16----折半查找
- Python一日一练03----一元二次方程的计算
- Python一日一练103----Django模版练习
- Python一日一练104----Django URLconf练习
- maven项目 无法运行main方法的问题。java.lang.ClassNotFoundException
- You Are All Excellent 排序
- SD卡哈发生地方很少的发生的
- 编写Android启动页面的方法
- Java final
- Python一日一练02----诗词生成器
- spark rdd countByValue
- InfoQ精选文档
- 可变参数, va_start, va_arg, va_end
- leetcode:String to Integer (atoi)
- FileStream和StreamReader,StreamWrite,BinaryWriter
- jni.h No such file or directory
- Python程序员必知必会的开发者工具
- db file parallel write,write complete waits