python class实现模拟购物车代码,python购物车,<python clas
python class实现模拟购物车代码,python购物车,<python class实现模拟购物车代码>1.[代码][Python]代码class ShoppingCart(object): """Creates shopping cart objects for users of our fine website.""" items_in_cart = {} def __init__(self, customer_name): self.customer_name = customer_name def add_item(self, product, price): """Add product to the cart.""" if not product in self.items_in_cart: self.items_in_cart[product] = price print product + " added." else: print product + " is already in the cart." def remove_item(self, product): """Remove product from the cart.""" if product in self.items_in_cart: del self.items_in_cart[product] print product + " removed." else: print product + " is not in the cart."my_cart=ShoppingCart("wangweiwei")my_cart.add_item("apple",12)
编橙之家文章,
class ShoppingCart(object): """Creates shopping cart objects for users of our fine website.""" items_in_cart = {} def __init__(self, customer_name): self.customer_name = customer_name def add_item(self, product, price): """Add product to the cart.""" if not product in self.items_in_cart: self.items_in_cart[product] = price print product + " added." else: print product + " is already in the cart." def remove_item(self, product): """Remove product from the cart.""" if product in self.items_in_cart: del self.items_in_cart[product] print product + " removed." else: print product + " is not in the cart."my_cart=ShoppingCart("wangweiwei")my_cart.add_item("apple",12)
编橙之家文章,
相关内容
- Python有道字典查询单词,python有道字典,在Ubuntu下,Py
- python随机生成手机号,python手机号,python随机生成手机
- Python配置JDK编程环境,pythonjdk编程,用Python配置JDK
- python提取京东商品url获取产品价格,python产品价格,京东
- python代码查询市级城市天气,python代码查询,python代码查
- 自动更新高清电影文件中文名python代码,高清python,自动
- 拉手网Python程序员面试题,拉手python,拉手网Python程序员
- 用python xmlrpc调用实现发布博文,pythonxmlrpc,用python xml
- python核心编程题代码实现,python核心编程代码,python核心
- python模块arcpy-要素工具箱脚本合集,pythonarcpy-,1.[代码
评论关闭