# 把多個帳號密碼寫入文件中# 編寫登陸功能,登陸失敗三次 程序退出。# 登陸帳號密碼定義,用列表分割,for循環取值=====判斷對錯=====循環條件3次退出# with open(r'db.txt',mode='r') as f:# db=f.read().split('|')# # print(db)# z=[]# for x in db:# y=x.split(':')# # print(y)# count=0# z.append(y)# print(z)# while True:# usr = input('username')# pwd = input('password')# if usr == z[0][0] and pwd == z[0][1]:# print('login in')# break# else:# print('error')# count+=1# if count>=3:# print('blocked')# break # for x in db: # z = x.split(':') # z.append(y) # count = 0 # while True: # usr = input('username') # pwd = input('password') # zz=[usr,pwd] # if zz in y: # print('login in') # break # else: # print('error') # count += 1 # if count >= 3: # print('blocked') # break# 1. 文件db2.txt內容:每一行內容分別爲商品名字,價錢,個數,求出本次購物花費的總錢數# apple 10 3# tesla 100000 1# mac 3000 2# lenovo 30000 3# chicken 10 3ttl=0count=0with open(r'db2.txt',mode='r') as f: db=f.read().split('\n') # print(db) for x in db: y=x.split(' ') # print(y) ttl+=int(y[1])*int(y[2]) count+=1 if count < 5: continue print(ttl)