日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

简易购物功能实现

發布時間:2025/7/14 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 简易购物功能实现 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

2019獨角獸企業重金招聘Python工程師標準>>>

#!?/usr/bin/env?python #coding:?utf-8#file:?market.py #Author:?toddlerya #date:?11-28-2014 #version:?1.0"""" 購物系統功能要求:1、前提必須指定用戶登錄進去,才可進行購買!2、登錄進去之后,提示用戶進行充值金額,否則無法進行購買物品!3、充值成功后,提示用戶是否進行購買(不購買直接退出系統)4、用戶同意購買之后,把所有產品列出供用戶選擇5、針對之前用戶充值的金額來判斷用戶哪些用戶不能買,并給予提示信息;能購買的話,把物品加入購物框6、如果用戶輸入的產品不存在,也給予相應的提示信息"""objects?=?['coffee','car','mobile','Internet','clothes'] prices?=?[35,30000,3000,6000,500] shop_list?=?[]name?=?"jojo" passwd?=?"bean" choose?=?"" choice?=?""def?login():while?True:name?=?raw_input("please?input?your?name:")if?name?==?"jojo":?password?=?raw_input("please?input?your?password:")while?password?!=?'bean':password?=?raw_input("please?input?your?password:")print?"----------------------------------"print?"welcome?to?login?to?system!\n"print?"----------------------------------"breakelse:print?"+-----------------------------+"print?"user?%s?not?found,try?again!"?%?nameprint?"+-----------------------------+"continue?def?recharge():global?self_sal?self_sal?=?(raw_input("please?store?your?money:?"))while?not?self_sal.isdigit():self_sal?=?raw_input('not?a?number,?please?try?again:?')self_sal?=?int(self_sal)while?True:if?self_sal?>?0:print?'\n--------------------------------------'print?'you?had?stored?%s?successfully!\n'?%?self_salbreakelse?:print?'---------------------------------'self_sal?=?int(raw_input("you?store?money?failure,\nplease?store?money?again:"))continuedef?shop():purchase?=?raw_input('Do?you?want?to?shop(yes/no):%s'?%?choose)if?purchase?==?'yes':for?i?in?objects:print?i,'\t',prices[objects.index(i)]elif?purchase?==?'no':print?'\n------------------------------------'print?'you?had?exited?system?successfully!'print?'----------------------------------'global?choicechoice?=?"!!!"F_choice?=?choice.strip()login() recharge() shop()while?choice?!=?"!!!":choice?=?raw_input("Please?input?one?item?to?buy(input?'!!!'?to?quit):?")F_choice?=?choice.strip()if?F_choice?==?"!!!":breakif?F_choice?in?objects:objects_index?=?objects.index(F_choice)objects_price?=?prices[objects_index]print?F_choice,'---->',objects_priceif?self_sal?>?objects_price:shop_list.append(F_choice)print?'Added?%s?into?shop?list'?%?choiceself_sal?=?self_sal?-?objects_priceprint?"Salary?left:",self_salchoice?=?""continueelse:if?self_sal?<?min(prices):print?'Sorry,rest?of?your?salary?cannot?buy?anything!88'print?"you?hava?bought?these?things:?%s"?%?shop_listbreakelse:print?"Sorry,you?cannot?afford?this?product,please?try?other?ones!\n"print?"-----------------------------------------------------------------"choice?=?raw_input("please?input?one?item?to?buy(input?'!!!'?to?quit):")F_choice?=?choice.strip()continueelse:print?"Not?such?products!Please?input?one?item?to?buy?again!(input?'!!!'?to?quit):"print?"-------------------------------------------------------"choice?=?raw_input("please?input?one?item?to?buy(input?'!!!'?to?quit):")?F_choice?=?choice.strip()continue


轉載于:https://my.oschina.net/u/2003106/blog/350223

總結

以上是生活随笔為你收集整理的简易购物功能实现的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。