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()
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.
Join our real-time social learning platform and learn together with your friends!