1 Star 0 Fork 0

北京大学-夏敏/小白学派森2.0

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
grammar.py 743 Bytes
一键复制 编辑 原始数据 按行查看 历史
陈俊宇 提交于 2020-11-10 17:48 . 作业:测试文件读取
from random import choice, seed, randrange
articles = ("a", "the","1","2","3","4","5","6","7","8","9","10")
nouns = ("cat", "dog", "sheep", "rabbit", "tiger", "chicken",
"fish", "grass", "seed", "carrot", "apple")
verbs = ("eats", "catches", "finds")
def sentence():
return noun_phrase() + verb_phrase()
def noun_phrase():
return [choice(articles), choice(nouns)]
def verb_phrase():
vp = [choice(verbs)]
if randrange(3) > 0:
vp.extend(noun_phrase())
return vp
def creat():
with open('data.txt','w')as txt:
seed()
for i in range(10000000):
txt.write(" ".join(sentence()))
txt.write('\n')
if __name__ == "__main__":
creat()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/pkuecho/xiaobai-xuepaisen-20.git
git@gitee.com:pkuecho/xiaobai-xuepaisen-20.git
pkuecho
xiaobai-xuepaisen-20
小白学派森2.0
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385