__author__ = 'Administrator'
#!/usr/bin/env python
# -*-coding:UTF-8-*-
def shoping():
balance=10000
while True:
with open("E:/product_list.txt",'r+') as f:
product_list=f.readlines()
print(product_list)
f.close()
allproduct=[]
allprice=[]
for i in range (0,len(product_list)):
productprice=product_list[i].split()
productproduct=productprice[0]
productprice=productprice[1]
allproduct.append(productproduct)
allprice.append(productprice)
buysomething=input('what do you want to buy? please input number:')
#检测账户余额是否足够
if buysomething.isdigit():
buysomething=int(buysomething)
print(allprice[buysomething])
if int(allprice[buysomething])<balance:
balance-=int(allprice[buysomething])
with open("E:/shop_list.txt",'a') as f2:#放入购物车
f2.write(str(allproduct[buysomething] +' '+ allprice[buysomething]+ '\n'))
print('your balance is %s'%balance)
with open("E:/shop_list.txt",'r+') as f3:#放入购物车
shopbuy=f3.readlines()
print(shopbuy)
f3.close()
def login():
f=open("E:/2.txt",'r+') #读取user配置文件。
cont=f.readlines() #readlines把读取的行当作元素返回一个列表
f.close()
allname=[] #初始化一个用户列表
allpasswd=[]
for i in range(0,len(cont)): #len获取cont列表的元素数量
onecont=cont[i].split() #循环取一行内容并分割成列表,split()以空格为分隔符分割字符串并返回一个列表。
onename=onecont[0] #循环取一行中的帐号
onepasswd=onecont[1] #
allname.append(onename) #循环把每一行取到的帐号追加到用户列表中
allpasswd.append(onepasswd)
lf=open("E:/3.txt",'r')
lcont=lf.readlines()
lf.close()
# print(lcont) #打印用户锁文件内容
# print(allname)
# print(allpasswd)
cont=0
while cont < 3:
username=input("login user:").strip()
passwd=input("password:")
if username not in allname:
print("No this accont!")
elif (username +"\n") in lcont:
print("your account has been locked!Please contact admin!")
break
else:
rel_passwd_index=allname.index(username) #取该帐号在用户列表中的索引,此时用户列表的索引和密码列表的索引是对应的,因此我们同样>取到了该帐号的密码在密码列表的索引
rel_passwd=allpasswd[rel_passwd_index] #取该帐号的真实密码
if passwd==rel_passwd:
print("Login success!")
break
else:
print("password is error!")
cont+=1
if cont >= 3:
print("Excessive password error,your account has been locked!Please contact admin!")
nf=open("E:/3.txt",'w')
nf.write(username+"\n")
nf.close()
def chioce():
print('--------------请选择-----------------')
print('1、查询余额')
print('2、取现')
print('3、还款')
print('4、转账')
print('5、退出')
print('------------------------------------')
# number = numif(input("请选择您的操作:"))
number=input("请选择您的操作:")
return number
def ATMlogin():
count_number=input("your count number:")
count_passwd=input("password:")
with open("E:/count.txt",'r+') as f_count:
count_list=f_count.readlines()
allcount=[]
allpswd=[]
allbalance=[]
for i in range(0,len(count_list)):
onecont=count_list[i].split()
onecount=onecont[0]
onepswd=onecont[1]
onebalance=onecont[2]
allcount.append(onecount)
allpswd.append(onepswd)
allbalance.append(onebalance)
if count_number not in allcount:
print('not this count')
elif count_number in allcount:
pswdindex=allcount.index(count_number)
countpassword=allpswd[pswdindex]
if count_passwd==countpassword:
print('yes ,you are PASS')
else:
print('password is wrong')
def bank():
chioce_number=chioce()
if chioce_number=='1':
print('查询余额')
if chioce_number=='2':
print('取现')
if chioce_number=='3':
print('还款')
if chioce_number=='4':
print('转账')
if chioce_number=='5':
print('退出')
exit()