zoukankan      html  css  js  c++  java
  • 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("没有查到当前编号对应的商品信息, 已退出")

     
  • 相关阅读:
    最方便建立进程池,线程池的方法
    python并发编程之多线程
    Cpython解释器支持的进程与线程
    进程与线程理论基础
    爬虫关于高性能方面
    Python中 and,or 的计算规则
    存储库之——MongoDB
    解析库之——beautifulsoup
    破解极验滑动验证码
    爬取拉勾网示例
  • 原文地址:https://www.cnblogs.com/mixiu26/p/7848889.html
Copyright © 2011-2022 走看看