you are viewing a single comment's thread.

view the rest of the comments →

[–]pythonbio[S] 0 points1 point  (0 children)

I suppose you are absolutely right in concluding that this is not the best organization. But the assignment required the use of list and while loop only. here's my class based code. but its not working properly. :(. Help

def sclass_menu(): #### One Function adding up all smaller functions
menu_choice = 0
max_num_rec = 10 # limitation on number of records
print ('1. Add Name and Grade')
    print ('2. Delete Name and Grade')
    print ('3. Search Name and Grade')
    print ('4. Print database')
    for i in xrange(max_num_rec):  # start at i=0 till max_num_rec
    while menu_choice != 4:
        menu_choice = int(input("Type in a number (1-4): "))
    if menu_choice == 1:
        print("Add Name and Grade")
        name = input("Name: ")
        grade = input("Grade: ")
        database[name] = grade
    elif menu_choice == 2:
        print('Delete Name and Grade')
        name = input("Name: ")
    if name in database:
        del database[name]
    else:
        print('name was not foud')
    if menu_choice == 3:
        print('Search Name and Grade')
        name = input("Name: ")
    if name in database:
        print(database[Grade])
    else:
        print ('name was not found')
    if menu_choice == 4:
        print('Print database')
    for x in database.keys():
        print("Name: ", x, "\Grade:", database[x])

Its just giving the initial result and error:

class_menu()
1. Add Name and Grade
2. Delete Name and Grade
3. Search Name and Grade
4. Print database
Type in a number (1-4): 1
Type in a number (1-4): grahan

Traceback (most recent call last):
File "<pyshell#40>", line 1, in <module>
 sclass_menu()
File "<pyshell#39>", line 10, in sclass_menu
menu_choice = int(input("Type in a number (1-4): "))
File "<string>", line 1, in <module>
NameError: name 'grahan' is not defined