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

shopping card

时间:2016-04-21 13:32:00      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

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‘)

 

shopping card

标签:

原文地址:http://www.cnblogs.com/Jinjunzmx/p/5416260.html

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