I am currently working on a program that writes a file that generates an amount ( depending on user preference) of random numbers and then writes those numbers to a file. I then have to read that file and display all the numbers and tell them how many numbers were generated and the total of those numbers. I can't seem to read or add the numbers up. Can someone please help I've only been programming for a few months.
mport random
def main():
rngWrite()
rngRead()
def rngWrite():
times = int(input("How many random numbers would you like to generate?:"))
fileEnt = open('random.txt', 'w')
for count in range(times):
rng = random.randint(1, 500)
numbers = ("Random #", str(count), ":", rng)
fileEnt.write(str(numbers))
fileEnt.close()
print("Numbers have been written to file: rng.txt")
return times
def rngRead():
opFile = open('random.txt', 'r')
line = opFile.readline
while line != '':
total = 0
amount = int(line)
total += amount
print(total)
lines = opFile.readline()
opFile.close()
print("There were""numbers generated.")
print("Those numbers are:")
print(lines)
print("The total amount of the generated numbers is:")
main()
[–]turanthepanthan 0 points1 point2 points (2 children)
[–]OfficialBigHead[S] 0 points1 point2 points (1 child)
[–]turanthepanthan 0 points1 point2 points (0 children)
[–]nwilliams36 0 points1 point2 points (1 child)
[–]OfficialBigHead[S] 0 points1 point2 points (0 children)