Small problems encountered by the student management system.

Student Management System:

all_info = { ' UZI ' : { ' name ' : ' UZI ' , ' age ' : ' 18 ' , ' tel ' : ' 9199999199 ' },
             ' xiye ' : { ' name ' : ' xiye ' , ' age ' : ' 20 ' , ' tel ' : '37402384702'}}

new_infor = {'name':'UZI','age':'18','tel':'9199999199',
             'name':'xiye','age':'20','tel':'37402384702'}

def zj_fun ():
    new_name = input( ' Please enter your name: ' )
     if   new_name in all_info.keys():
             print ( ' Your input is wrong! ' )

    else:
        new_age = input( ' Please enter your age: ' )
        new_tel = input( ' Please enter your contact information ' )

        new_infor ['name'] = new_name
        new_infor ['age'] = new_age
        new_infor ['tel'] = new_tel
    all_info [new_name] = new_infor
    print(all_info)


def sc_fun ():
    new_name = input( ' Please enter your name: ' )
     if new_name in all_info.keys():
        all_info.pop(new_name)
    else :
         print ( ' Your input is wrong! ' )
     print (all_info)



def g_fun ():
    new_name = input( ' Please enter your name: ' )
     if new_name in all_info.keys():
        new_age = input( ' Please enter your age: ' )
        new_tel = input( ' Please enter your contact information ' )
        all_info[new_name]['age'] = new_age
        all_info[new_name][ ' tel ' ] = new_tel
     else :
         print ( ' Your input is wrong! ' )
     print (all_info)



def cx_fun():
     for k,v in all_info.items():
         print ( ' Name: %s ' % k)
         print ( ' Age: %s ' % v[ ' age ' ])
         print ( ' Contact information: % s ' % v[ ' tel ' ])


zj_fun()

 A few small problems encountered:

in can directly query whether the object is in the key of the dictionary. No need to loop through each key.

In a dictionary, traversal and change are used at the same time, which is prone to error. dictionary changed size during iteration

'method' object is not subscriptable means the code has incorrect use of parentheses. Change [] to ()

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325414273&siteId=291194637