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‘)
时间: 2024-10-17 19:44:05