Ask your own question, for FREE!
Computer Science 24 Online
OpenStudy (anonymous):

Ok this function works perfectly, I just need to know how do i make it so it so the random integers that are generated, are written to the mynumbers.txt file. def main(): #Open a file for writing outfile = open ('mynumbers.txt' , 'w') #Generate random integer number from random import randint number = randint(6, 12) print("Write will create", number, "random numbers") import random i = 0 while i < 11: # Get random number in range 10 through 20. n = random.randint(10, 20) print(n) i += 1 main()

OpenStudy (rsmith6559):

outfile.write( something ) outfile.close() If you're going to use the code on Windows, Windows still has a "wb" mode of file writing. If I remember correctly, when you read the file, you'll have to convert the numbers to numbers, it will read as a string.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!