Skip to content

Les11_2 #24

Description

@kostyria

import collections
pets = {}
pets[0] = 0

def create():
last = collections.deque(pets, maxlen=1)[0]
id = last + 1
pets[id] = {}
name = str(input(f'Введите имя питомца: '))
pets[id][name] = {
'Вид питомца': '',
'Возраст питомца': 0,
'Имя владельца': ''
}
type = str(input(f'Вид питомца: '))
pets[id][name]['Вид питомца'] = type
age = int(input(f'Возраст питомца: '))
pets[id][name]['Возраст питомца'] = age
owner = str(input(f'Имя владельца: '))
pets[id][name]['Имя владельца'] = owner
print('Запись о питомце добавлена!')
return True

def read(id):
if id in pets:
name = get_name(id)
age = int(str(pets[id][name]['Возраст питомца'])[-1])
god = get_suffix(age)
print(f'Это {pets[id][name]["Вид питомца"]} по кличке "{name}". Возраст питомца: {pets[id][name]["Возраст питомца"]} {god}. Имя владельца: {pets[id][name]["Имя владельца"]}')
return True
else:
print('питомец не найден')
return False

def update(id):
if id in pets:
name = get_name(id)
type = str(input(f'Вид питомца: '))
pets[id][name]['Вид питомца'] = type
age = int(input(f'Возраст питомца: '))
pets[id][name]['Возраст питомца'] = age
owner = str(input(f'Имя владельца: '))
pets[id][name]['Имя владельца'] = owner
print('Запись о питомце изменена!')
return True
else:
print('Питомец не найден')
return False

def delete(id):
if id in pets:
del pets[id]
print('Запись удалена!')
return True
else:
print('Питомец не найден')
return False

def get_pet(id):
if id > 0 in pets.keys():
return print(pets[id])
else:
return False

def get_name(id):
for name in pets[id]:
return name

def get_suffix(age):
god = ''
if age in range(11, 15) or age in [0, 5, 6, 7, 8, 9]:
god = 'лет'
elif age == 1:
god = 'год'
else:
god = 'года'
return god

def pets_list():
for id in pets:
get_pet(id)
return True

command = str(input('Введите команду: '))
while command != 'stop':
if command == '':
print('Пустая строка')

elif command == 'create':
    create()
    
elif command == 'read':
    id = int(input('Введите id питомца: '))
    read(id)  
        
elif command == 'update':
    id = int(input('Введите id питомца: '))
    update(id)

elif command == 'delete':
    id = int(input('Введите id питомца: '))
    delete(id)
    
elif command == 'pets_list':
    pets_list()
   
command = str(input('Введите команду: '))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions