【题目】
- 名片管理系统
使用python语言设计并完成一个名片管理系统,需要包含以下功能:
- 程序启动时,显示系统主界面,用户可以看到功能菜单;
- 提示用户输入,根据不同的数字进入不同的功能模块;
- 新建名片,用户可以添加姓名、电话、邮箱等信息至名片;
- 查询,根据姓名查询名片信息,并可以选择执行修改和删除操作;
- 商店收银系统
使用python语言设计并完成一个商店收银系统,需要包含以下功能:
- 程序启动时,提示管理员进行登录,登录成功后进入主界面;
- 提示输入,根据不同的数字进入不同的功能模块;
- 输入1进入商品上架功能,并提示输入商品名称和商品价格;
- 输入2进入商品下架功能,根据所输入商品名称删除该商品;
- 输入3进入金额计算功能,提示输入所购买的商品名,根据所有的商品名计算总价,并添加找零功能。
- 输入4退回到登录界面。
【要求】
- 请注意截止时间,过时不予补交!
- 需要将详细解答过程以文字或截图方式展示!
- 提交后在平台上查看并确认是否提交成功!
- 若发现抄袭现象,双方均以0分处理!1.
1.代码
## 代码实现
# 以下是该名片管理系统的代码实现。
# ```python
# 名片管理系统
cards = [] # 存储所有名片信息的列表
def show_menu():
"""显示系统主界面"""
print("=" * 40)
print(" " * 14 + "名片管理系统")
print("=" * 40)
print(" " * 11 + "1. 新建名片")
print(" " * 11 + "2. 查询名片")
print(" " * 11 + "3. 显示所有名片")
print(" " * 11 + "4. 退出系统")
print("=" * 40)
def add_card():
"""新建名片"""
print("=" * 40)
name = input("请输入姓名:")
phone = input("请输入电话:")
email = input("请输入邮箱:")
card = {"id": len(cards) + 1, "name": name, "phone": phone, "email": email}
cards.append(card)
print("名片已保存!")
def find_card():
"""查询名片"""
print("=" * 40)
name = input("请输入要查询的姓名:")
for card in cards:
if card["name"] == name:
print("姓名:{}".format(card["name"]))
print("电话:{}".format(card["phone"]))
print("邮箱:{}".format(card["email"]))
choice = input("请选择要执行的操作:\n1. 修改名片\n2. 删除名片\n3. 返回主菜单\n")
if choice == "1":
update_card(card)
elif choice == "2":
delete_card(card)
elif choice == "3":
return
break
else:
print("未找到名片!")
def update_card(card):
"""修改名片"""
print("=" * 40)
print("请输入新的信息(不修改的信息直接回车):")
name = input("请输入姓名[{}]: ".format(card["name"]))
phone = input("请输入电话[{}]: ".format(card["phone"]))
email = input("请输入邮箱[{}]: ".format(card["email"]))
if name:
card["name"] = name
if phone:
card["phone"] = phone
if email:
card["email"] = email
print("名片已更新!")
def delete_card(card):
"""删除名片"""
print("=" * 40)
choice = input("确定要删除该名片吗?[Y/N]")
if choice.lower() == 'y':
cards.remove(card)
print("名片已删除!")
def show_all_cards():
"""显示所有名片"""
print("=" * 40)
print(" " * 15 + "所有名片")
print("=" * 40)
print("{:<5} {:<10} {:<15} {:<20}".format("ID", "姓名", "电话", "邮箱"))
print("-" * 40)
for card in cards:
print("{:<5} {:<10} {:<15} {:<20}".format(card["id"], card["name"], card["phone"], card["email"]))
print("=" * 40)
def main():
"""程序主函数"""
while True:
show_menu()
choice = input("请输入数字选择功能:")
if choice == "1":
add_card()
elif choice == "2":
find_card()
elif choice == "3":
show_all_cards()
elif choice == "4":
print("再见!")
break
else:
print("输入有误,请重新输入!")
if __name__ == '__main__':
main()
运行结果:
2.代码
# 商店收银系统
# 登录函数,返回True表示登录成功,返回False表示登录失败
def login():
username = input('请输入用户名:')
password = input('请输入密码:')
if username == 'YJH' and password == '42104521':
print('登录成功!')
return True
else:
print('用户名或密码错误,请重新输入!')
return False
# 商品上架函数,将商品名称和价格添加到字典中
def add_product():
name = input('请输入商品名称:')
price = input('请输入商品价格:')
products[name] = price
print('商品上架成功!')
# 商品下架函数,根据商品名称从字典中删除商品
def remove_product():
name = input('请输入商品名称:')
if name in products:
del products[name]
print('商品下架成功!')
else:
print('该商品不存在!')
# 金额计算函数,根据输入的商品名称计算总价和找零
def calculate_price():
total = 0
while True:
name = input('请输入商品名称(输入0结束):')
if name == '0':
break
if name in products:
total += float(products[name])
else:
print('该商品不存在!')
print('总价为:%.2f' % total)
paid = float(input('请输入支付金额:'))
change = paid - total
print('找零为:%.2f' % change)
# 主函数,根据用户输入的数字选择不同的功能模块
def main():
while True:
print('请选择功能:')
print('1. 商品上架')
print('2. 商品下架')
print('3. 金额计算')
print('4. 退出登录')
choice = input('请输入数字:')
if choice == '1':
add_product()
elif choice == '2':
remove_product()
elif choice == '3':
calculate_price()
elif choice == '4':
break
else:
print('输入错误,请重新输入!')
# 程序入口,登录成功后进入主函数
if __name__ == '__main__':
products = {}
while True:
if login():
main()
else:
continue
运行结果
感谢内生原动力(自己)
听从自己内心的声音,做自己想做的人!!!