Wondering why I am not getting output into a file with this code. The loop is not working it is only catching the last entry. Whatever the last score I put in is what goes in the file. I have tried everything that I can think of or find online. The program jumps to main() back to def main(): then to testfile and I get an error that reads global name open is not defined, then the program terminates. Any help would be great. Thanks! def main(): #num_tests = 0 testfile = open('tests.txt', 'w') #### THIS RUNS -- but no output ##### for count in range(1, 6): test = float(input('Enter the test score: #' + \ str(count) + ' % ')) #test1 = int(input('Enter test number 1: % ')) #test2 = int(input('Enter test number 2: % ')) #test3 = int(input('Enter test number 3: % ')) #test4 = int(input('Enter test number 4: % ')) #test5 = int(input('Enter test number 5: % ')) testfile.write(str(test) + '\n') #testfile.write(str(test) + '\n') #testfile.write(str(test) + '\n') #testfile.write(str(test) + '\n') #testfile.write(str(test) + '\n') testfile.close() print('The scores are in the text file.') main()
input
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)