2018-04-02 python实现购物

product_list = [

('Iphone',7000),

('Mac Pro',12000),

('Bycle',10000),

('StarBuck Latte',36),

('Wathc',16000),

('Alex Python',120),

]

shopping_list = []

salary =input("Please your salary:")

if salary.isdigit():

salary =int(salary)

while True:

for index,itemin enumerate(product_list):

print(index,item)

user_choice =input("Want to own it? :")

if user_choice.isdigit():

user_choice =int(user_choice)

if user_choice =0:

print(len(product_list))

p_item = product_list[user_choice]

if p_item[1]<=salary:

shopping_list.append(p_item)

salary -= p_item[1]

print("Added %s into shopping cart,your current balance is \033[31:1m%s\033[0m" %(p_item,salary))

else:

print("\033 [31:1m Your balance is insufficient! \033 [0m")

else:

print("Without the goods!!!!")

elif user_choice =="q":

print("--------shoppint list---------")

for pin shopping_list:

print(p)

print("Your current balance: ",salary)

exit()

else:

print("Invalid option!!!!!")

你可能感兴趣的:(2018-04-02 python实现购物)