I would like to print all the tests that a user has participated in. This is my code:
def report(testFile, userEntry):
testFile = open("test.txt", "r")
for line in testFile:
lineWithoutNewLine = line.rstrip('\n')
userRecord = lineWithoutNewLine.split(';') # making the line a list
userName = userRecord[0]
subject = userRecord[1]
user = userRecord[2]
score = userRecord[3]
grade = userRecord[4]
if userRecord[0] == userEntry:
testFile = open("test.txt", "r")
print(userRecord)
More code that may give more insight into my program:
if (subject == 'history' or subject == 'History') and (unit == 'WWII' or unit == 'ww2'):
with open("hisEasy.txt", "a") as hisWw2File:
for hisEasy in quizzes:
userName = hisWw2[0]
subject = hisWw2[1]
unit = hisWw2[2]
score = hisWw2[3]
grade = hisWw2[4]
hisWw2File.write(userName + ';' + subject + ';' + unit + ';' + str(score) + ';' + grade + '\n')
if subject == 'history' or subject == 'History' and unit == 'Hitler' or unit == 'hitler':
with open("hisMedium.txt", "a") as hisMediumFile:
for hisH in tests:
userName = hisH[0]
subject = hisH[1]
unit = hisH[2]
score = hisH[3]
grade = hisH[4]
hisHFile.write(userName + ';' + subject + ';' + unit + ';' + str(score) + ';' + grade + '\n')
The test file contains all the tests any user has every taken. For Example:
['qwe', 'history', 'ww2', '65', 'C']
['abc', 'maths', 'trigonometry', '80', 'A']
I want to go through all the tests and print all the tests that the username of the user currently logged in took. How would I improve my code to do this?
quiz.txt.