python-练习4

python-练习4_第1张图片

代码如下:

from operator import add
notice='''\
welcome to my shopping car
1 iphone 5800
2 book 100
3 bike 200
4 iphone8 8000\
'''
amount=raw_input('You amount in credict card')
items=[5800,100,200,8000]
name={'1':'iphone','2':'book','3':'bike','4':'iphone8'}
sum1=[0]
named=[]
print notice

while True:
    choice=raw_input(">>>")
    if choice.isdigit():
        if ((reduce(add,sum1)+items[int(choice)-1])1])
            named.append(name[choice])
            print 'added [', name[choice], '] to your shopping'
        else:
            print 'please try another one'
    if choice=='q':
        print'====================================='
        print 'goods                         price'
        for i in range(1,len(sum1)):
            print named[i-1],'                      ',sum1[i]
        print 'sum:',reduce(add,sum1)
        print 'balance',int(amount)-reduce(add,sum1)

你可能感兴趣的:(python)