나는 재미있는 프로그램을 만들고있다. 이것은 X 양의 파일을 Y의 랜덤 0과 1로 채우도록 입력해야합니다.중첩 루프 및 파일 io
이 파일을 실행할 때 각 파일에 20 개의 임의 0과 1로 채워진 2 개의 파일을 갖고 싶습니다. 내가 이것을 실행할 때 첫 번째 파일 만 채워지고 두 번째 파일은 비어있게됩니다.
제 두 번째 루프와 관련이 있다고 생각하지만 잘 모르겠습니다. 어떻게 작동합니까?
import random
fileamount = int(raw_input("How many files should I make? > "))
amount = int(raw_input("How many characters in the files? > "))
print "I will now make %r files with %r characters in them!\n" % (fileamount, amount)
s1 = 0
s2 = 0
while s2 < fileamount:
s2 = s2 + 1
textfile = file('a'+str(s2), 'wt')
while s1 < amount:
s1 = s1 + 1
textfile.write(str(random.randint(0,1)))