‘‘‘
Shopping Small Program:
Enter payroll first when user starts
Print a list of items after the user starts the program
Allow users to select items to buy
Allows users to continue to buy a variety of products
Check if the balance is sufficient at the time of purchase, if you have enough direct debit, the print balance is insufficient
Allow the user to exit the program voluntarily and print the list of purchased items when exiting
‘‘‘
Salary=input ("Input You Salary:")
If Salary.isdigit ():
Salary=int (Salary)
Else
Exit ("Invalid data type ...")
Welcome_msg= ' Welcome to Shopping mall '. Center (50, '-')
Print (WELCOME_MSG)
product_list=[
(' Iphone ', 5888),
(' Mac Air ', 8000),
(' Mac Pro ', 9000),
(' Xiaomi ', 19.9),
(' Coffee ', 30),
(' Tesla ', 820000),
(' Bike ', 900),
(' cloth ', 200)
]
Shop_car=[]
Exit_flag=false
While not exit_flag:
Print (' Product List '. Center (50, '-'))
#for Product_item in Product_list:
#p_name, P_price = Product_item
"' For P_name,p_price in product_list:
Print (P_name,p_price) "
For item in Enumerate (product_list):
INDEX=ITEM[0]
P_NAME=ITEM[1][0]
P_PRICE=ITEM[1][1]
Print (Index,p_name,p_price)
User_choice=input ("[Q=quit,c=check]what do you want to buy?:")
If User_choice.isdigit (): #肯定是选择商品
User_choice=int (User_choice)
If User_choice<len (product_list):
P_item=product_list[user_choice]
If p_item[1]<salary:
Shop_car.append (P_item) #放入购物车
Salary-=p_item[1] #减钱
Print ("Added [%s] into shop car,your current balance is [%s]"% (
P_item,salary))
Else
Print ("Your balance is [%s],can not afford this ..." %salary)
Else
If user_choice== ' Q ' or user_choice== ' quit ':
Print ("Purchased products as Belows:". Center (40, ' * '))
For item in Shop_car:
Print (item)
Print ("End". Center (40, ' * '))
Print ("Your balance is [%s]"%salary)
Exit_flag=true
Elif user_choice== ' C ' or user_choice== "check":
Print ("Purchased products as Belows:". Center (40, ' * '))
For item in Shop_car:
Print (item)
Print ("End". Center (40, ' * '))
Print ("Your balance is [%s]"%salary)
Python Learning Day4--python Basics-Shopping Applet