I'm trying to generate a list of random odd numbers in a specific range with the length of the list generated by calling another random number in PYTHON (and then writing them to a file).
I've been able to generate the initial random number (and threw in a display caller to see what it was). When I try to use it as the length of the list of the other of randomly generated numbers it doesn't work. I'm not certain why. Any insight would be appreciated. Here's what I've got...
import random
def main():
digit_file = open("numbers.txt","w")
file_size = random.randint(4,7)
print (file_size)
print ("is the file size\n" )
for n in range(file_size):
rand_output = random.randint(5,19)
if n %2 != 0:
print(rand_output)
digit_file.write(str(rand_output))
digit_file.close
print("File was created and closed.")
main()
Aucun commentaire:
Enregistrer un commentaire