PYTHONWrite a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 100. The application should let the user specify how many random numbers...




PYTHONWrite a program that writes a series of random numbers to a file. Each random number should be in the range of 1 through 100. The application should let the user specify how many random numbers the file will hold.I have a program written and I keep running into an error when I enter a number. The error says: " line 15, in main

outfile.write(str(num)+'')

ValueError: I/O operation on closed file."

Any ideas what I can do to fix it? Program is below. Thank you in advance!!!


import random

#main function

def main():

#program message

print("Random Number File Generator")

#prompt user to enter total numbers

count=int(input("How many random numbers should file hold:"))

#create new text file

outfile=open('random numbers writer.txt','w')

#loop to genertate random numbers and write it in file

while count!=0:

num=random.randint(1,100)

#write random generated number into text file

outfile.write(str(num)+'')

count-=1

outfile.close()

main()




May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here