I'm currently practicing on python language and I try to make a sample program that will Add, Show, Delete and Update students info.. But I have this error "global name 'b' is not defined" on the 'Show()', 'Delete()' & 'Update()'.. please help me me guys..Thank you..
x = 1
y = 1
z = 1
q = 1
f = {}
print(' W E L C O M E')
print(' Please select a choice')
print('*******************************************************************')
print('Enter "1" to add student[s]')
print('Enter "2" to show the list of student[s]')
print('Enter "3" to update student[s]')
print('Enter "4" to delete student[s]')
print('*******************************************************************')
print('Please type the word "start()" to launch/re-launch the application. ')
def start():
choice = input('Enter choice number:')
print(' ')
if choice == '1':
Add()
elif choice == '2':
Show()
elif choice == '3':
Update()
elif choice == '4':
Delete()
else:
print('Invalid choice!')
def Add():
while x ==1:
Add_student = input('Add Student[s]? Y/N: ')
if Add_student =='y' or Add_student == 'Y':
a = input('Student ID: ')
b = input('Name: ')
c = input('Age: ')
d = input('Course: ')
e = input('Year: ')
f.update({a:{'Name':b, 'Age':c, 'Course':d, 'Year':e}})
else:
break
def Show():
while y ==1:
Show_student = input('Show student[s] list?Y/N:')
if Show_student == 'y' or Show_student == 'Y':
w = input('Enter ID:')
print('Name:',b)
print('Age:',c)
print('Course:',d)
print('Year:',e)
f.update({w:{'Name':b, 'Age':c, 'Course':d, 'Year':e}})
else:
break
def Update():
while z ==1:
Update_student = input('Update student[s] info?Y/N: ')
if Update_student == 'Y' or Update_student == 'y':
del_stud = input('Enter Student ID: ')
del(f[del_stud])
new_name = input('Name: ')
new_age = input('Age: ')
new_course = input('Course: ')
new_year = input('Year: ')
f.update({del_stud:{'Name':new_name, 'Age':new_age, 'Course':new_course, 'Year':new_year}})
print(f)
print(b, 'has been updated!')
else:
break
def Delete():
while q==1:
Delete_student = input('Delete Student[s]?Y/N: ')
if Delete_student == 'Y' or Delete_student == 'y':
del_stud_ID = input('Student ID: ')
del(f[del_stud_ID])
print(f)
print(b, 'has been deleted!')
else:
break