Ask your own question, for FREE!
Computer Science 16 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
HeyItsAlicia: Mits midnight!!! Happy 16th bday to me !!
8 minutes ago 15 Replies 4 Medals
XShawtyX: Art
4 hours ago 1 Reply 1 Medal
RAVEN69: My drawing so far is actually fire
1 week ago 9 Replies 2 Medals
PureSoulless: is staying at your friend's house while you're homeless legal.
2 weeks ago 5 Replies 1 Medal
whyjustwhy: i did that one TV girl trend with blake (aka @ShadowKid3)
1 week ago 12 Replies 2 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!