码迷,mamicode.com
首页 > 其他好文 > 详细

购物车

时间:2016-11-22 19:56:12      阅读:207      评论:0      收藏:0      [点我收藏+]

标签:enter   for   sdi   type   git   this   dig   off   cts   

#! /usr/bin/env python
# -*- coding:utf-8 -*-
salary = input("Input your salary:")
if salary.isdigit():
    salary = int(salary)
else:
    exit("Invalid date type")
product_list = [
    (iphone, 4800),
    (mac_book, 8888),
    (coffee, 30),
    (tesla, 820000),
    (bike, 800),
    (zhoucaibang, 0.01)
]
shop_car = []
# print(product_list)
exit_flag = False
while exit_flag is not True:
    print("product list".center(50, -))
    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("quit,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:  # can‘t buy
                shop_car.append(p_item)
                salary -= p_item[1]
                print("Adder [%s] into shop car,you 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 below".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 below".center(40, *))
            for item in shop_car:
                print(item)
            print("END".center(40, *))
            print("Your balance is [%s]" % salary)
        else:
            print("Invalid date type")

 

购物车

标签:enter   for   sdi   type   git   this   dig   off   cts   

原文地址:http://www.cnblogs.com/lifei-python/p/6090425.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!