import pickle
filename=input('Enter a file name:')
def commands():
f=open(filename,'w')
names=[]
grades=[]
while True:
name=input("Give a student's name:")
if name.lower()=='end':
f.close()
print("File closed")
print("Back to Menu")
break
else:
x=names.append(name)
f.write(str(x))
grade=input("Give student's grade:")
try:
grade=float(grade)
if 0<=grade<=10:
y=grades.append(grade)
f.write(str(y))
else:
print("Please give a grade!Between 0-10! ")
except ValueError:
print(grade,"is not a number...Give only Numbers!")
def syn2(filename):
try:
f=open(filename,'r')
f.read(names)
f.read(grades)
d1={}
d1[names]=grades
print(d1)
print("Back to Menu")
except IOError:
return False
当我调用 syn2(filename) 时:
回溯(最近一次通话最后): 文件“file1.py”,第 68 行,在 文件“file2.py”,第 45 行,在 syn2 中 NameError:未定义全局名称“名称”