Ask your own question, for FREE!
Computer Science 7 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!
Latest Questions
Arriyanalol: i need help
12 hours ago 7 Replies 1 Medal
Arriyanalol: CONGRATS to me
15 hours ago 8 Replies 2 Medals
Legomaster346: What colleges are good that are near Arab Alabama?
1 week ago 5 Replies 0 Medals
Arriyanalol: i need help
1 week ago 6 Replies 2 Medals
Arizona: does anyone know the percentage rate of 30,000 and 40,000
1 week ago 0 Replies 0 Medals
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!