加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
random-sentences.py 1.20 KB
一键复制 编辑 原始数据 按行查看 历史
Jérôme Krell 提交于 2019-10-10 14:22 . Reformat Code by PyCharm-Community
"""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 助手
尝试更多
代码解读
代码找茬
代码优化