Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help with these Programs in Python 3.2 . The Random Number File Reader wi

ID: 3538254 • Letter: I

Question

I need help with these Programs in Python 3.2 . The Random Number File Reader will use the the Random Number File Writer in its programming. Random Number File Writer. Write 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. and for the second part the File Reader: This exercise assumes you have completed the programming exercise , Random Number File Writer. Write another program that reads the random numbers from the file, display the numbers, and then display the following data: The total of the numbers The number of random numbers read from the file

Explanation / Answer

#Random Number File Writer

import random

n=input("Enter number of random numbers to generate:")

n2=int(n)

with open('randomNumbers.txt', mode='w') as a_file:

for i in range(0,n2):

s=random.randint(1,100)

s2=str(s)+" "

a_file.write(s2)


#Random Number File Reader

n=0

sum=0

with open('randomNumbers.txt') as a_file:

for a_line in a_file:

s=a_line.rstrip().split()

n=n+len(s)

for num in s:

print(num)

sum=sum+int(num)

print("The total of the numbers is: "+str(sum))

print("The number of random numbers read from the file is: "+str(n))