本質上,如果我輸入n爲4,k輸入4,則應該在文件中返回4行4位二進制字符串。如何在文件中返回(k)二進制字符串的位數?
取而代之,它返回四行二進制,但是按照位的升序。 (所以,第一行有一個位,第二行有兩個,第三行有三個,等等。)
這裏是我的代碼:
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()
感謝您的幫助!
非常感謝!我知道這是一個簡單的修復,但我無法弄清楚。 – Sinopia