# _*_coding:utf-8_*_
# Author:len liu
'''
user_passwd.txt 文件格式为 egon|egon123|len|len123|wxx|123|lxx|456
'''
shop_list = [
("iphone",5000),
("coffer",80),
("疙瘩汤",50),
("python book",30),
("bike",800),
("vivox9",2980),
]
buy_list = []
count = 0
while True:
user_input = input("pls input username:").strip()
passwd_input = input("pls input password:").strip()
with open('user_passwd.txt', 'r') as f:
login_user_pass=f.read().split('|')
if user_input in login_user_pass and passwd_input == login_user_pass[login_user_pass.index(user_input) +1]:
print("login sucessful!")
saraly = input("pls input your saraly:").strip()
if saraly.isdigit():
saraly = int(saraly)
print("this is shopping list:")
while True:
for i in shop_list:
print(shop_list.index(i), i)
choice = input("pls input your choice:").strip()
if choice.isdigit():
choice = int(choice)
if choice < len(shop_list) and choice >= 0:
p_info = shop_list[choice]
#print(p_info[1])
if p_info[1] <= saraly:
buy_list.append(p_info[0])
saraly -= p_info[1]
print("you got %s , your have buy %s ,your balance is %s" % (p_info[0],buy_list,saraly))
else:
print("you not enough moneny! show your buylist %s and your balance is %s!" % (
buy_list, saraly))
else:
print("no this product")
elif choice == 'q':
print("show your buylist %s and your balance is %s!" % (buy_list, saraly))
exit()
else:
print("invaid option,if want complete buy anything pls enter 'q'")
# else:
# print("input error,pls input digital:")
else:
print("invalid username or password")
count +=1
if count >2 :
print("your count try too times,byebye!")
break