【发布时间】:2014-03-31 00:28:02
【问题描述】:
我无法弄清楚如何编写一个脚本,该脚本基本上将一堆随机字母保存到 不同 行的 .txt 文件中。我现在拥有的是:
import random
f = open("test.txt", "w") #clears current test.txt file
f.close()
f = open("test.txt", "a")
b = 0
def randomstring():
global c
valid_letters='abcdefghijklmnopqrstuvwxyz'
c = ''.join(random.choice(valid_letters))
while b < 10000:
randomstring()
f.write(c + "/n")
b = b + 1
f.close
这个输出是什么
q/ne/ny/nt/nb/ng/nf/no/nu/ni/nr/nn/nh/nu/nr/ne/nx/nw/nr/nt/ns/nw/nk/nz /no/nb/nk/nh/nx/nj/nw/nu/no/nl/nv/nm/ni/nh/nd/nh/ng/nk/np/nd/na/no/nx/nn/ng /nb/np/nh/nb/nx/nj/nj/ne/nr/nb/nu/nr/nh/nj/nf/nw/ns/nl/np/nc/ne/nh/np/nu/nc /nw/nd/nt/nt/na/nk/np/nc/nm/nt/nt/nb/nw/nf/nf/nf/na/ni/n
我希望它输出的是
q
e
是的
t
等。谢谢
【问题讨论】:
-
如果我的回答有帮助,您介意接受吗?谢谢
标签: python python-3.x random