用python实现宠物管理系统

PETS = []  #全局变量

def add_pet():
	ID = input("请输入宠物编号:")
	name = input("请输入宠物名称:")
	category = input("请输入宠物种类:")
	price = input("请输入宠物价格:")
	pet = {'id':ID,'name':name,'category':category,'price':price}
	PETS.append(pet)
	print("恭喜宠物添加成功!")

def search_pet():
	name = input("请输入宠物名称:")
	for pet in PETS:
		if pet['name'] ==name:
			text = "编号:{},名称:{},种类:{},价格:{}".format(
				pet['id'],
				pet['name'],
				pet["category"],
				pet['price']
				)
			print(text)

def delete_pet():
	ID = input("请输入宠物编号:")
	for pet in PETS:
		if pet['id'] == ID:
			PETS.remove(pet)
			print("删除宠物成功!")
			break

def list_pet():
	for pet in PETS:
		text = "编号:{},名称:{},种类:{},价格:{}".format(
				pet['id'],
				pet['name'],
				pet["category"],
				pet['price']
				)
		print(text)

def main():
	print('='*30)
	print('1.添加宠物')
	print('2.查找宠物')
	print('3.删除宠物')
	print('4.列出宠物')
	print('5.退出宠物')
	print('='*30)

	while True:
		option = input("请输入选项:")

		if option == '1':
			add_pet()
		elif option == '2':
			search_pet()
		elif option == '3':
			delete_pet()
		elif option == '4':	
			list_pet()
		elif option == '5':	
			break
		else:
			print("请输入正确的选项")
main()
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值