while True:
msg = '''
1 register
2 check'''
print(msg)
choice=input('please input the index:').strip()
if choice == '1':
phone = input('Please input phone number:').strip()
name = input('name:').strip()
pwd = input('password:').strip()
sex = input('gender:').strip()
with open('db.txt','at', encoding='utf-8')as f:
f.write('%s,%s,%s,%s\n'%(phone,name,pwd,sex))
elif choice == '2':
phone = input('please input phone number:').strip()
with open('db.txt','rt', encoding='utf-8'):
for line in f:
if line.startswith(phone):
print(line, end='')
break
else:
print('illegal input')
C:\Users\user\AppData\Local\Programs\Python\Python36\python.exe “C:/Users/user/PycharmProjects/hellow python/test.py”
1 register
2 check
please input the index:1
Please input phone number:123
name:raimond
password:456
gender:male
1 register
2 check
please input the index: