Homework: Shopping Malls
1, commodity display, price
2. Bank card balance
3. Pay the bill
The program flowchart is as follows:
The code is as follows:
Shopdisplay = {' clothes1 ': ' 498 ', ' Jeans ': ' $ ', ' shoes ': ' 289 ', ' hat ': ' A ', ' clothes2 ': ' 599 '}print (Shopdisplay) Shoppingcartprice = [] #购物车商品价格ShoppingCart = {} #购物车while true:thing = input ("Want to BU Y: ") Price = shopdisplay['%s '%thing] shoppingcart.update ({'%s '%thing: '%s '%price}) Shoppingcartprice.append ( '%s '% price) answer = input ("Does want to continue buy something else? Please say yes or no:\n ") if answer = = ' Yes ': Continue Else:breakdef shit (): #判断余额是否 Greater than the item to be bought sum = 0 Totalmoney = $ for i in shoppingcartprice:sum = sum + int (i) Totalmoney = Tota Lmoney-sum if Totalmoney > 0:a = input ("Does really want to buy tins?" Please enter Yes or no!\n ") if a = = ' Yes ': print (" Successful,wish you a Happy shopping!\n ") Else : Print ("Thanks come to My") exit () Else:print ("Sorry,you has not enough moneY! Please remove somethings!\n ") sum = 0TotalMoney = 1000for i in shoppingcartprice:sum = sum + int (i) Totalmoney = Tot ALMONEY-SUMIF Totalmoney > 0:a = input ("Does really want to buy tins?" Please enter Yes or no!\n ") if a = = ' Yes ': print (" Successful,wish you a Happy shopping!\n ") exit () El Se:exit () else:print ("Sorry,you has not enough money! Please remove somethings!\n ") while True:print (" Your shopping cart has this thing:\n ") print (SHOPPINGCA RT) Print ("If you don't want to del,please enter '. ') \ n ") del_thing = input (" Please input the goods so you don't want to buy:\n ") if del_thing = = '. ': Break s = shoppingcart['%s '% del_thing] shoppingcart.pop ('%s '% del_thing) Shoppingcartprice.remo ve (s) #删除不买的东西shit ()
Code is very simple, the operation of the basic implementation of the function, will look at it .... Later to optimize
Python Job shopping Mall