shopping card

keypoints:

1:define a list as shopping list

2: list operation :enumerate

3:the  conception

weakness:

without any fuction used .

 

#!/usr/bin/python
# -*- coding: utf-8 -*-
print ('welcome to shopping mall')
print ('%-5s  %-10s  %-10s'  %('p_id','gname','price'))
pro_list=[('apple',10),('pair',20),('orange',30),('banana',40)]
for index,i in enumerate(pro_list):
        print ('%-5s  %-10s  %-10s' % (index+1,i[0],i[1]))
total = input('please input your recharge :')
shopping_card=[]
flag = ture
while flag:
        num = input ('please select menu: input num | shopping(s) |quit(q) |check(c)|pay(p) :')
        if num == s :
            num1=input ('please input what you want to buy:')
            if num1.isdigit() is false:
                print ('invalid,please re-fill')
            if num1<len(pro_list) and num1>0:
                shopping_card = shopping_card.append(pro_list[num1])
            else:
                print (' your input is incorrect')
        elif num == c :
            amount = 0
            for index , s in enumerate(shopping_card):
                print ('index, s[0],s[1]')
        elif num == p :
            amount = 0
            for goods in pay_cart:
                amount+=goods[1]
                conf = input('complete payment: Y')
                if conf == y :
                   left = total - amount   
                   if left >0 :
                      pay_cart = shopping_card
                      shopping_card=[]
                      total = left
                      print ('shopping_lists%  Cost_moneys%' % (pay_cart,amount))
                   else :
                        print ('not enough moeny')
        elif num==q:
            if shopping_cart:
                print ('you are shopping,do you want quit, Y ')
                qu = input('quit : y | shopping : N')
                if qu == y:
                        flag = false
                else :
                        print ('enjoy your shopping')
            else:
                flag = false
                print('thanks for your shopping')

 

转载于:https://www.cnblogs.com/Jinjunzmx/p/5416260.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值