Hello all! I was able to make a program that writes random numbers to a file depending on how many the user requests. I now need to write a program that read those numbers...prints them... then at the end adds all the numbers from each line together and adds them. I think I probably am not using the for loop properly.
Here is what I have so far.. len shows 0 and so does the total.
def main(): amount = 0.0 total = 0.0 infile = open('randomnumbers.txt', 'r') ##Read lines from file then print next line line = infile.readline() while line != '': num = line.rstrip('\n') print(num) line = infile.readline() ## Add numbers from lines together for num in infile: amount = int(num) total = amount + amount print(total) #Show total number of numbers in file. print(len(line)) infile.close() main()