I'm having some trouble with AND and OR within if else statements. This is my code:
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 topic == 'history' or topic == 'History' and unit == 'Hitler' or difficulty == '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')
I'm trying to print the scores of tests to text files according to subjects and units but it actually saves it to BOTH text files. For example, if my unit is ww2 it will save to ww2 file AND to the Hitler unit file. Any ideas how to fix this?
Aucun commentaire:
Enregistrer un commentaire