大家好,所以我創建一個學生成績的菜單,我想進入一個學生的名字,並使用鹹菜2個測驗成績。一旦輸入這些成績,我想創建一個報告,並且在我嘗試爲我的菜單選項2搜索單個學生並向菜單選項三顯示所有學生時,但每次嘗試打印時都會收到錯誤代碼它。錯誤代碼試圖加載個別的學生級菜單,所有學生
import pickle
def menu():
selection = input("0\tExit"
"\n1\tEnter Student Name/Grades"
"\n2\tIndividual Report"
"\n3\tReports"
"\nEnter Menu Number: ")
if selection == "0":
systemExit()
if selection == "1":
studentData()
if selection == "2":
singleReport()
if selection == "3":
studentReports()
def systemExit():
exit()
def studentData():
name = input("Enter Student Name: ")
quiz1 = input("Enter Quiz 1: ")
quiz2 = input("Enter Quiz 2: ")
with open("pStudent_Quiz_Grades.p", "ab") as pFile:
pickle.dump((name, (quiz1, quiz2)), pFile)
clearScreen()
return()
def clearScreen():
print("\n" * 5)
return()
def singleReport():
pFile = open("pStudent_Quiz_Grades.p", "rb")
grades_dict = pickle.load(pFile)
search = input("Enter a Name to Search: ")
for name in grades_dict:
if name.upper() == search.upper():
print(name+": "+str("pStudent_Quiz_Grades.p"[name]))
def studentReports():
pFile = pickle.load(open("pStudent_Quiz_Grades.p", "rb"))
print(pFile)
while True:
menu()
什麼錯誤和在哪一行? – aBiologist
你必須添加該錯誤。 – hasanghaforian
誤差基本上是「高清singleReport()」和「高清studentReports()」,但該錯誤代碼,我得到的是針對「高清singleReport():」它說「元組對象有沒有屬性」,並在「高清studentReports():」我試圖讓所有學生的成績展現出來,但只有一個顯示出來@aBiologist – Bray98