1 Star 0 Fork 0

dzc/Python-1

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
random-sentences.py 1.21 KB
一键复制 编辑 原始数据 按行查看 历史
faresbessrour 提交于 2017-10-24 05:18 +08:00 . Pythonized more
"""Generates Random Sentences
Creates a sentence by selecting a word at randowm from each of the lists in
the following order: 'article', 'nounce', 'verb', 'preposition',
'article' and 'noun'.
The second part produce a short story consisting of several of
these sentences -- Random Note Writer!!
"""
import random
article = ["the", "a", "one", "some", "any"]
noun = ["boy", "girl", "dog", "town", "car"]
verb = ["drove", "jumped", "ran", "walked", "skipped"]
preposition = ["to", "from", "over", "under", "on"]
def random_int():
return random.randint(0,4)
def random_sentence():
"""Creates random and return sentences."""
return ("{} {} {} {} {} {}"
.format(article[random_int()]
,noun[random_int()]
,verb[random_int()]
,preposition[random_int()]
, article[random_int()]
,noun[random_int()])).capitalize()
# prints random sentences
for sentence in list(map(lambda x: random_sentence(), range(0, 20))):
print(sentence)
print("\n")
story = (". ").join(list(map(lambda x: random_sentence(), range(0, 20))))
# prints random sentences story
print("{}".format(story))
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sdredboy/Python-1.git
git@gitee.com:sdredboy/Python-1.git
sdredboy
Python-1
Python-1
master

搜索帮助