Shopping Cart (registration, login, shopping cart, checkout)

shopping_car_dict=dict()
money=[0]
def input_username_pwd():
username=input('username:')
pwd=input('pwd:')
return username,pwd
def goods_get():
with open('goods.txt','r',encoding='utf8')as fr:
fr1=fr.read()
fr2=eval(fr1)
return fr2
fr2=goods_get()

the Register DEF ():
Print ( 'Welcome to the registration function:')
username, pwd = input_username_pwd ()
with Open ( 'user_info.txt', 'A', encoding = 'utf8') AS FA:
fa.write (f '{username}: {pwd} |')
DEF the Login ():
Print ( 'Welcome to the login function:')
username, pwd = input_username_pwd ()
username1 = f '{username}: {pwd}'
with Open ( ' user_info.txt ',' r ', encoding =' utf8 ') AS fr:
fr2 = fr.read ()
USERNAME2 = fr2.split (' | ')
IF username1 in USERNAME2:
Print (' Login successful ')
the else:
Print ( 'wrong password')

Shopping DEF ():
Print ( 'Welcome to the shopping paradise:')
the while True:
for IND, Goods in the enumerate (fr2):
Print (f 'Product Code IND} {', Goods)
Choice = the INPUT ( 'Please select product numbers, exit press Q: ')
IF Choice ==' Q ':
BREAK
Choice = int (Choice)
goods = FR2 [Choice]
Print (F' {goods} successful purchase of goods, \ n-')
goods_name goods = [0 ]
IF goods_name in shopping_car_dict:
shopping_car_dict [goods_name] +. 1 =
the else:
shopping_car_dict [goods_name] =. 1
Money [0] + = goods [. 1]
Print (F 'you buy goods are {shopping_car_dict}, the total price is {money [ 0]} ')

shopping_car DEF ():
Print ( 'Welcome to the cart function:')
the while True:
Print (f 'you buy goods that {shopping_car_dict}, the total price is Money {[0]}')
Choice = the INPUT ( 'please enter the product number you want to delete, quit, press q: ')
IF Choice ==' q ':
BREAK
shopping_car_dict [Choice] - = 1
for goods in fr2:
for Choice in goods:
Money [0] - = goods [1 ]
DEF the pay ():
Print ( 'Welcome to the payment Center')
Print (f 'you buy goods that {shopping_car_dict}, the total price is Money {[0]}')
Choice = the INPUT ( 'press Y to confirm payment or y, empty cart press N or n-: ')
IF Choice ==' Y'or Choice == 'Y':
Print (F 'you have paid {money [0]} membered purchased goods are {shopping_car_dict } ')
elif Choice ==' N'or Choice == 'n-':
shopping_car_dict.the Clear ()
Money [0] = 0
Print ( 'cart is empty')
the else:
Print ( 'invalid input')

func_msg = '' '
1: Registration
2: Log
3: Shopping
4: Cart
5: Consumer
' ''
func_choice = {
'1': the Register,
'2': the Login,
'3': Shopping,
'4': shopping_car ,
'5': the Pay,
}
the while True:
Print (func_msg)
LC = the iNPUT ( 'enter the function you want to select, press exit q:')
IF LC == 'q':
BREAK
the else:
func_choice LC

Guess you like

Origin www.cnblogs.com/jinhongquan/p/11354821.html