EDITED:
import pickle
filename=input('Enter a file name:')
def entoles():
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
WHEN I CALL syn2(filename) :
Traceback (most recent call last): File "C:/Users/ΕιΟήνη -2-/Desktop/irstavr Exercise1 Seira3.py", line 68, in File "C:/Users/ΕιΟήνη -2-/Desktop/irstavr Exercise1 Seira3.py", line 45, in syn2 NameError: global name 'names' is not defined
why does it happens? How can i fix it? I have made many changes over and over...but the result stays the same...it doesnt work! :(