1 1.view code2'''
3knowledge_point:
41.練習if...else;
52.練習while;
63.練習列表的切片取值;78
requirements:
9購物車:
101.程式啟動後,輸入工資,列印商品列表
112.提示使用者根據商品編號購買產品
123.選擇商品後檢測餘額是否足夠,扣款或提醒餘額不足
134.隨時退出,退出時列印已經購買的商品和餘額
1415
code:
16'''
17 product_li =[
18 ("
mac pro
", 12000),
19 ("
hp", 5000),
20 ("
iphone
", 6000),
21 ("
huawei
", 5000),
22 ("
gopro
", 4000)23]
24 salary = input("
input salary: ")
25 shopping_li =
26if
salary.isdigit():
27 salary =int(salary)
28while
true:
29for i, item in
enumerate(product_li):
30print(i+1, item)
31 choice_num = input('
輸入編號購買:')
32if
choice_num.isdigit():
33 choice_num =int(choice_num)
34if choice_num <= len(product_li) and choice_num >=0:
35 paid_price = product_li[choice_num-1][1]
36if paid_price <=salary:
37 paid_item = product_li[choice_num - 1]
38print("
you can pay")
3940 salary -=paid_price
41print("
surplus is \033[32;1m{}\033[0m
".format(salary))
42else:43
print('
\033[41;1m not enough money {}\033[0m
'.format(salary))
44else:45
print("
product is not exist")
46elif choice_num == "q"
:47#print("exited")
48print('
---------shopping_list_as_follows-------------')
49for p in
shopping_li:
50print
(p)51
print("
current balance is {}
".format(salary))
52 exit() #
退出53
else:54
print("
invalid choice
")
python後端部署 前後端專案部署
一.準備工作 前面有具體步驟 2.修改python3的環境變數,寫入到 etc profile中 path opt python36 bin usr local sbin usr local bin usr sbin usr bin opt ruby bin root bin 3.修改 bashrc...
後端工具集
判斷索引是否存在 param indexname return public boolean i istsindex string indexname actionget return response.i ists 重新建立索引 補救措施 如果索引誤刪 自動建立新的索引 postconstruct...
《python 題庫集之基礎練習》
一 單項選擇題 本大題共10小題,每小題2分,共20分 1 想用乙個變數來表示出生年份,下列命名中 項最可取。b a.b y b.birth year c.birthyeard.birthyear 2 假設有兩個變數分別是x和y,其中x 3,y 5,以下選項中,不能交換兩個變數中的值。a a.x y...