# @Version : 1.0
# @Author : FENG
from 房屋出租系统.house__oop import *
def main():
# 显示菜单
while True:
main_mune()
key = int(input("请输入(1-6:)"))
if key in [1, 2, 3, 4, 5, 6]:
if key == 1:
add_house()
elif key == 2:
select_house_by_id()
elif key == 3:
del_house()
elif key == 4:
updata()
elif key == 5:
show_house()
elif key == 6:
if exit():
break
if __name__ == "__main__":
main()
print("此次系统结束,欢迎下次操作".center(32, "="))
# @Version : 1.0
# @Author : FENG
houses = [{"id": 1, "name": "tim", "phone": "113", "address": "海鼎", "rent": 800, "state": "未出租"}]
id_counter = 1
def main_mune():
print("主\t菜\t单".center(32, "="));
print("\t\t\t1.新 增 房 源")
print("\t\t\t2.查 找 房 源")
print("\t\t\t3.删 除 房 源")
print("\t\t\t4.修 改 房 源")
print("\t\t\t5.房 屋 列 表")
print("\t\t\t6.退 出")
pass
def add_house():
print("添加房屋".center(32, "="))
name = input("姓名:")
phone = input("电话:")
address = input("地址:")
rent = int(input("租金:"))
state = input("状态:")
global id_counter
id_counter += 1
house = {"id": id_counter, "name": name, "phone": phone, "address": address, "rent": rent, "state": state}
houses.append(house)
print("房屋添加成功".center(32, "="))
pass
def find_by_id(find_id):
for house in houses:
if house["id"] == find_id: # 字典用【】来访问key 对应的value
return house
return None
pass
def select_house_by_id():
Aid = int(input("请输入要查找的id(1-6):"))
if find_by_id(Aid):
house = find_by_id(Aid)
print("编号\t\t房主\t\t电话\t\t地址\t\t月租\t\t状态(未出租/已出租)")
for value in house.values():
print(value, end="\t\t")
print(f"编号为{Aid}的房屋信息展示完毕".center(32, "="))
else:
print("房屋编号不存在,查询失败...".center(32, "="))
pass
def updata():
updata_id = int(input("请选择待修改房屋id:(-1退出)"))
if updata_id == -1:
print("您放弃修改房屋信息".center(32, "="))
return
house = find_by_id(updata_id)
if not house:
print("没有要修改的房屋信息".center(32, "="))
return
# 回车表示不修改
name = input(f"姓名({house['name']}): ")
if len(name) > 0:
house['name'] = name
phone = input(f"电话({house['phone']}): ")
if len(phone) > 0:
house['phone'] = phone
address = input(f"地址({house['address']}): ")
if len(address) > 0:
house['address'] = address
rent = input(f"租金({house['rent']}): ")
if len(rent) > 0:
house['rent'] = rent
state = input(f"状态({house['state']}): ")
if len(state) > 0:
house['state'] = state
print(f"编号id为{updata_id}的房屋信息更新完成".center(32, "="))
pass
def del_house():
print("删除房屋信息:".center(32, "="))
del_id = int(input("请输入待删除房屋的id(-1退出):"))
if del_id == -1:
print("放弃删除房屋信息".center(32, "="))
return
while True:
key = input("请输入选择(Y/N)")
if key.lower() == 'y' or key.lower() == 'n':
break
if key.lower() == 'y':
if find_by_id(del_id):
house = find_by_id(del_id)
houses.remove(house)
print(f"删除编号为{del_id}房屋成功".center(32, "="))
else:
print("房屋编号不存在,删除失败...".center(32, "="))
pass
def show_house():
print("房屋列表".center(60, "="))
print("编号\t\t房主\t\t电话\t\t地址\t\t月租\t\t状态(未出租/已出租)")
for house in houses:
for value in house.values():
print(value, end="\t\t")
print()
print("房屋信息显示完毕:".center(60, "="))
pass
def exit():
print("请输入你的选择(Y/N),请确认选择:")
while True:
key = input("请输入选择(Y/N)")
if key.lower() == 'y' or key.lower() == 'n':
break
if key.lower() == 'y':
return True
pass
运行展示( 部分)