예제 #1
0
def edit(): #4.3 редактирование

    data, is_empty = db.load_from_pickle()

    if is_empty == False:
        s = input('Type sign of the car you want to edit: ')
        fl = 0

        for i in range (len(data)):

            if (data[i]['sign'] == s):
                fl = 1
                k = input('If you want to change model of the car type 1, if power - type 2: ')

                if k == '1':
                    new_m = input('Enter new model of the car: ')
                    if (new_m.isalpha() == True):
                        data[i]['model'] = new_m
                        db.save_to_pickle(data)
                    else:
                        print('Error! Model should contain only letters.')

                elif k == '2':
                    new_p = input('Enter new power ot the car: ')
                    if (new_p.isdigit() == True):
                        data[i]['power'] = new_p
                        db.save_to_pickle(data)
                    else:
                        print('Error! Power should contain only numbers.')

                else:
                    debug.incorrect_operation()

        if fl == 0:
            print('There is no such car in database')
예제 #2
0
def search_m(): #поиск по названию

    data, is_empty = db.load_from_pickle()

    if is_empty == False:
        fl = input('If you want to find cars with model containing certain string type 1, if you want to search by the whole name of the model type 2: ')

        if fl == '1':
            search_str_in_m(data)
        elif fl == '2':
            search_model(data)
        else:
            debug.incorrect_operation()
예제 #3
0
def search_op_dict(): #4.2 поиск операции в словаре и запуск функции по ключу словаря

    operation = debug.inter_operation()
    funcs = {'insert': insert_cars, 'out': out_cars, 'search power': search_p, 'search model': search_m, 'edit car': edit, 'delete car': delete, 'move car': move}
    keys = list(funcs.keys())
    fl = 0

    for i in keys:
        i = str(i)

        if i == operation:
            fl = 1
            funcs[i]()

    if fl == 0:
        debug.incorrect_operation()
예제 #4
0
def search_p(): #поиск по мощности

    data, is_empty = db.load_from_pickle()
    
    if is_empty == False:

        max_power, min_power = search_max_min_p(data)
        fl = input('If you want to find cars with power more than certain number print 1, less - print 2 and if you want to find cars with power between two numbers print 3: ')

        if fl == '1':
            search_more_p(data,max_power)

        elif fl == '2':
            search_less_p(data,min_power)
        
        elif fl == '3':
            search_middle_p(data,min_power,max_power)

        else:
            debug.incorrect_operation()