【发布时间】:2017-08-23 14:47:33
【问题描述】:
基本上,如果我为 n 输入 4,为 k 输入 4,它应该在文件中返回 4 行 4 位二进制字符串。
相反,它返回四行二进制,但按位升序排列。 (所以第一行有一个位,第二行有两个,第三行有三个,依此类推。)
这是我的代码:
import random
def makeStrings():
fileName = str(input("file:"))
outputFile = open(fileName, "w")
userInput = str(input("k:"))
anotherinput = str(input("n:"))
counter = 0
while (counter < int(anotherinput)):
stringy = ""
for i in range(int(userInput)):
RandoNumber=int(random.random()*2)
stringy=stringy+str(RandoNumber)
outputFile.write(str(stringy) + "\n")
counter = counter +1
outputFile.close()
感谢您的帮助!
【问题讨论】: