|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
dict1={}
num=input("省份证件号:")
name=input("姓名:")
num2=input("房间号:")
num3=input("房费:")
num4=input("押金:")
A=open("信息表.text","a")
A.write(num+","+name+","+num2+","+num3+","+num4+","+"\n")
A.close()
B=open("信息表.text","r")
for eachline in B:
dict1[eachline[0:18]]=eachline[18:]
print(eachline[0:18])
print("1:查询住户信息 2:修改住户信息 3:添加住户 4:删除住户")
B.close()
Ch=int(input("请选择:"))
if Ch==1:
Ch1=input("请输入身份证件号:")
print(dict1[Ch1])
elif Ch==2:
[i][b][b][b][b][b][u] Ch1=input("请输入身份证件号:")
print(dict1[Ch1])
R=open("信息表.text","w")
dict[Ch1]=int(input("请按照顺序填写信息:"))
for k,v in dict1.items():
R.write(k+","+v)
R.close()
elif Ch==3:
D=open("信息表.text","a")
num=input("省份证件号:")
name=input("姓名:")
num2=input("房间号:")
num3=input("房费:")
num4=input("押金:")
D.write(num+","+name+","+num2+","+num3+","+num4+","+"\n")
D.close()
else:
E=open("信息表.text","w")
Ch1=input("请输入身份证件号:")
dict1.pop(Ch1)
for k,v in dict1.items() :
E.write(k+","+v)
E.close()
问题
elif2 跑不了
姓名:王话
房间号:11
房费:100
押金:1000
109999999999999999
1:查询住户信息 2:修改住户信息 3:添加住户 4:删除住户
请选择:2
请输入身份证件号:109999999999999999
,王话,11,100,1000,
请按照顺序填写信息:,刘信,11,100,1000
Traceback (most recent call last):
File "D:\pathon\酒店入住系统1.py", line 24, in <module>
dict1[Ch1]=int(input("请按照顺序填写信息:"))
ValueError: invalid literal for int() with base 10: ',刘信,11,100,1000'
>>>
先谢过各位
#Author: 聂嘉辉
#Date: 2020-08-15
class user():
def __init__(self, ID, name, roomID, roomrate, deposit):
self.ID = ID
self.name = name
self.roomID = roomID
self.roomrate = roomrate
self.deposit = deposit
def __str__(self):
return self.name
class hotel():
def __init__(self):
with open('信息表.text', 'a'):
pass
print('1:查询住户信息\n2:修改住户信息\n3:添加住户\n4:删除住户')
choice=int(input('请选择:'))
if choice == 1:
ID = input('请输入身份证件号:')
with open('信息表.text', 'r') as file:
for line in file:
if ID in line:
temp = line.split(',')[0:-1]
temp = user(temp[0], temp[1], temp[2], temp[3], temp[4])
print(F'姓名:{temp.name}\n身份证号:{temp.ID}\n房间号:{temp.roomID}\n房费:{temp.roomrate}\n押金:{temp.deposit}')
elif choice == 2:
old_ID = input('旧的身份证件号:')
with open('信息表.text','r') as file:
ID = input('身份证件号:')
name = input('姓名:')
roomID = input('房间号:')
roomrate = input('房费:')
deposit = input('押金:')
lines = file.readlines()
for line in range(len(lines)):
if old_ID in lines[line]:
lines[line] = F'{ID}, {name}, {roomID}, {roomrate}, {deposit}, \n'
with open('信息表.text','w') as file:
file.writelines(lines)
elif choice == 3:
with open('信息表.text','a') as file:
ID = input('身份证件号:')
name = input('姓名:')
roomID = input('房间号:')
roomrate = input('房费:')
deposit = input('押金:')
file.write(F"{ID}, {name}, {roomID}, {roomrate}, {deposit}, \n")
elif choice == 4:
with open('信息表.text','r') as file:
ID = input('身份证件号:')
lines = file.readlines()
for line in range(len(lines)):
if ID in lines[line]:
del lines[line]
with open('信息表.text','w') as file:
file.writelines(lines)
else:
print("输入有误!")
while True:
hotel()
|
|