python『学习之路01』python 购物车精简版

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2017/11/17 1:52
# @Author : mixiu26
# shopping.py

public_list = [
("iphone",5800),
("Mac Book",11800),
("Bike",1200),
("Wtach",10600),
("Coffee",31),
("Book",66)
]
Shopping_list = []
Salary = input("Input your salary: ")
if Salary.isdigit():
salary = int(Salary)
while True:
for item in public_list:
print(public_list.index(item),item) # index --- >返回指定元素索引
user_choice = input("请选择您需要的商品 >>>>: ")
if user_choice.isdigit():
choice = int(user_choice)
if choice >=0 and choice < len(public_list):
p_item = public_list[choice]
if p_item[1] <= salary:
Shopping_list.append(p_item)
# 余额扣款:
salary -= p_item[1]
print("Add %s into shppoing cart, your current balance is 33[31;1m%s33[0m" %(p_item,salary))
else:
print("33[41;1m你的余额仅剩[%s], 请充值: 33[0m" % salary)
else:
print("The Product code [%s] your Input is not exist! " % choice)
elif user_choice == "q":
print("===================== shopping list ========================")
for i in Shopping_list:
print(i)
print("Your current balance: ",salary)
exit()
else:
print("没有查到当前编号对应的商品信息, 请重新输入: ")
else:
print("没有查到当前编号对应的商品信息, 已退出")

 
【推广】 免费学中医,健康全家人
原文地址:https://www.cnblogs.com/mixiu26/p/7848889.html