Python練習購物選單

2021-07-31 14:19:59 字數 2309 閱讀 6438

要求:

1.展現商品選單及其**

2.輸入欲採購的總金額

3.輸入商品名稱進行採購,如果錢足夠購買**最低商品,則可一直購買,否則提示餘額不足,是否要進行充值,如果進行充值則總金額增加,可以繼續購物。

4.在開始部分要求對輸入進行判斷,必須為整形int,否則報錯重新輸入

5.在選擇物品清單的時候,可以輸入「?」號進行幫助,幫助內容包括list清單(當前購買的商品都有哪些,且中途充值了一共多少錢,當前餘額還剩下多少。)、back(返回上一級選單)、quit(退出系統)

item_list = ['aa','bb','cc','dd','ee','ff','gg','hh'] #商品列表

price_list = [5,8,6,3,1,12,24,990] #商品**

purchase_list = #購物車

deflatest_list

():for ab in purchase_list:

print ab #列印購物車清單

dict()

amount_money = 0

one = 0

for i in item_list:

print i,price_list[item_list.index(i)] #列印商品及商品**

while

true:

try:

salary = int(raw_input("please input your salary:").strip())

break

#確定輸入為整形

except valueerror:

print ("please input number,not string!")

continue

while one == 0:

select_item = raw_input("please input your select item name below:").strip()

if select_item == '?':

help_action = raw_input("\033[32mlist display all of your purchase list.\n"

"back return to the higher level menu.\n"

"quit exit this purchase system.\n\033[0m"

"please input your decide:").strip()

if help_action == 'list':

latest_list()

print

'your add top-up amount is:',amount_money

print

'your remaining amount is now:',salary

continue

elif help_action == 'back':

one == 1

elif help_action == 'quit':

sys.exit()

elif select_item == 'quit':

sys.exit()

for a in item_list:

if a == select_item:

salary = salary - price_list[item_list.index(a)] #剩餘金額

if salary < min(price_list):

last = raw_input("your money is not enough to buy another something! will you to top-up (yes/no)?").strip()

if last == 'yes':

top_money = int(raw_input("please input your top-up money:").strip())

amount_money += top_money

salary = salary + top_money #充值金額

one == 1

elif last == 'no':

print ("thank you ! byebye~~")

sys.exit()

elif salary >= min(price_list):

continue

python練習 多級選單

基本功能 1.可依次選擇進入各子選單 2.可從任意一層往回退到上一層 3.可從任意一層退出程式 使用說明 通過輸入進入各子選單,輸入 u 返回上一級選單,輸入 q 退出程式。menu 網易 google 中關村 汽車之家 youku 上地 昌平 北航 天通苑 回龍觀 朝陽 東城 上海 閘北 浦東 山...

python 利用列表練習購物系統

輸入工資 salary int input 請輸入你的工資 列印商品列表 goods iphone 100 iphone2 200 iphone3 300 判斷是否可以購買,可以加入購物車,不可以提示 num 1 for temp in goods print num,temp 0 temp 1 n...

Python高階例項練習 商場購物

python基礎練習 列表與函式 product list hw p 3500 iphone 500 watch 200 book1 10 lili money 5000 shopping input 請輸入物品編號 if shopping.isdigit shopping int shopping...