1. 程式人生 > >python--購物車

python--購物車

linux


#!/usr/bin/env python
#coding:utf-8
__author__ = "mmm"

‘‘‘
@author:sum
@file:shopping car.py
@time:7/12/1710:48 PM
@desc
‘‘‘

iphone = 0
book = 0
bike = 0
money = input("請輸入賬戶金額:")
list = {(‘iphone‘,8000),
        (‘book‘,100),
        (‘bike‘,200)}

for i in enumerate(list):
    a = i[0]
    b = i[1][0]
    c = i[1][1]
    print a,b,c

while True:
    num = raw_input("請輸入商品序號:")
    if num == ‘0‘:
        if money > 200:
            money = money-200
            bike = bike +1
            print ‘賬戶余額%s‘ %money
        else:
            print ‘余額不足‘
    if num == ‘1‘:
        if money > 100:
            money = money -100
            book = book +1
            print ‘賬戶余額%s‘ %money
        else:
            print ‘余額不足‘
    if num == ‘2‘:
        if money > 8000:
            money = money -8000
            iphone = iphone +1
            print ‘賬戶余額%s‘%money
        else:
            print ‘余額不足‘

    if num == ‘quit‘:
        print ‘購買清單 iphone %s \n        book %s\n        bike %s\n‘ %(iphone,book,bike)
        print ‘賬戶余額 %s‘ %money
        break


python--購物車