Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加了输出到文件的功能,以及加多了一句名人名言 #209

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,5 @@ venv.bak/
__pycache__/
test/
.vscode/
.gitignore
.gitignore
result.txt
3 changes: 2 additions & 1 deletion data.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@
"德国a, 只有在人群中间,才能认识自己。b",
"史美尔斯a, 书籍把我们引入最美好的社会,使我们认识各个时代的伟大智者。b",
"冯学峰a, 当一个人用工作去迎接光明,光明很快就会来照耀着他。b",
"吉格·金克拉a, 如果你能做梦,你就能实现它。b"
"吉格·金克拉a, 如果你能做梦,你就能实现它。b",
"古人a, 莫看江面平如镜,要看水底万丈深。b"
],
"bosh":[
"现在, 解决x的问题, 是非常非常重要的. 所以, ",
Expand Down
37 changes: 24 additions & 13 deletions 自动狗屁不通文章生成器.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,32 @@ def 来点名人名言():

def 另起一段():
xx = ". "
xx += "\r\n"
xx += "\n"
xx += " "
return xx

if __name__ == "__main__":
xx = input("请输入文章主题:")
for x in xx:
tmp = str()
while ( len(tmp) < 6000 ) :
分支 = random.randint(0,100)
if 分支 < 5:
tmp += 另起一段()
elif 分支 < 20 :
tmp += 来点名人名言()
else:
tmp += next(下一句废话)
tmp = tmp.replace("x",xx)
print(tmp)

flag = input("是否输出到文件?>>(y/n)")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两个建议:

  • 用 getopt 设置运行参数
  • 选项名用中文命名,以便与今后添加的更多选项相区分

木兰语言重现项目 供参考。

if flag.lower() == "y":
flag = True
else:
flag = False


tmp = str()
while ( len(tmp) < 6000 ) :
分支 = random.randint(0,100)
if 分支 < 5:
tmp += 另起一段()
elif 分支 < 20 :
tmp += 来点名人名言()
else:
tmp += next(下一句废话)
tmp = tmp.replace("x",xx)
print(tmp)
if flag:
with open("result.txt", "w") as f:
f.write(tmp)
print("\n结果已输出到result.txt!")