#Brett Hoeft
#ISYS 110-002
#Ferris State University
#Program that will write a random sequence of code 1-500 to a file

def main():
random_num()
num_file()

We Will Write a Custom Essay Specifically
For You For Only \$13.90/page!

order now

def random_num():
import random

random.randint(1,501) #setting parameters for random number file

fileOne=open(‘randomnumbers.txt’,’w’) #writing to the randomnumbers.txt file
#file one is data containing the code for the random numbers

try:
generatedNum=int(input(“What is the desired number?”)) #asking user for desired amount of random numbers

for iteration in range(1,generatedNum +1): #setting parameters for number if generated numbers to be display based on input

num=random.randint(1,501)

fileOne.write(str(num)+ ‘
‘) #writing file to display random numbers in vertical order using

except:

print(“Please use a value greater than one”) #error for wrong input

fileOne.close()

def num_file():
fileOne= open(‘randomnumbers.txt’,’r’) #reading number file to be displaye within randomnumbers file

overalltotal=0 #setting to value zero to have display of random number

runtotal=0

while line !=”:
showNum=int(line)

overalltotal+=showNum

print(str(showNum)) #displaying the interger produced by show number

runtotal+=1

print(“Running total of randoms numbers are:”, overalltotal) # displaying total of random generated numbers

average=overalltotal/runtotal #formula to calculate the average of values

#displaying average of numbers generated = total/
print(“Average of the specified numbers are”,average)

fileOne.close()

main()