Я хочу вычислить заметки класса из Folder.txt
с note_calculate
. И я могу также рассчитать оценки. После расчета я вставляю в список (который называется allnames
). После этого я перенес информацию из этого списка в новую txt-папку под названием Namesandnotes.txt
. Проблема начинается сейчас. Я хочу написать Passed Students
и Failed Students
в папке .txt
. «CC» и более высокие оценки должны писать в Passed Students.txt
, более низкие оценки должны писать в Failed Students.txt
. Но в коде я не могу писать имена и оценки от Namesandgrades.txt
до Пройдено и не выполнено. Это моя проблема.
def note_calculate(line):
line = line[:-1]
list1 = line.split(",")
name = list1[0]
note1 = int(list1[1])
note2 = int(list1[2])
final = int(list1[3])
son = note1 * (3/10) + note2 * (3/10) + final * (4/10)
passed = []
failed = []
if (son >= 90):
grade = "AA"
elif (son >= 85):
grade = "BA"
elif (son >= 80):
grade = "BB"
elif (son >= 75):
grade = "CB"
elif (son >= 70):
grade = "CC"
elif (son >= 65):
grade = "DC"
elif (son >= 60):
grade = "DD"
elif (son >= 55):
grade = "FD"
else:
grade = "FF"
return name +","+ grade
with open("Folder.txt","r", encoding="utf-8") as file:
allnames = list()
for i in file:
allnames.append(note_calculate(i))
with open("Namesandnotes.txt","r+", encoding = "utf-8") as file2:
for a in allnames:
file2.write(a + "\n")
with open("Namesandnotes.txt","r", encoding="utf-8") as file3:
passed = list()
failed = list()
text = file3.read()
print(text)
for line in file3:
line = line[:-1]
line_element = line.split(",")
if (line_element[1] == "AA"):
passed.append(line_element[1] + "\n")
elif (line_element[1] == "BA"):
passed.append(line_element[1] + "\n")
elif line_element[1] == "BB":
passed.append(line_element[1] + "\n")
elif line_element[1] == "CB":
passed.append(line_element[1] + "\n")
elif line_element[1] == "CC":
passed.append(line_element[1] + "\n")
else:
failed.append(line_element[1] + "\n")
with open("PassedStudents.txt","r+",encoding="utf-8") as file4:
for x in passed:
file4.write(x + "\n")
with open("FailedStudents.txt", "r+", encoding="utf-8") as file5:
for c in failed:
file5.write(c + "\n")