python葵花寶典 購物車

2021-09-24 22:47:49 字數 1468 閱讀 1024

goods = [,,

,,

,]fei_yong = 0

shop_car ={} #列表的鍵==序號,列表的值==商品

money = input("請輸入你的金額")

if money.isdigit():

#這是真錢

while true:

for i in range(len(goods)):

print(i+1,goods[i]["name"],goods[i]["price"])

#***************===商品展示***************===

choose = input("請輸入你要購買的商品(n/結算--q/退出)")

if choose.isdigit() and 0 < int(choose) <= len(goods):

#讓使用者輸入商品序號並判斷是不是數字以及在正常列表內

int_index = int(choose) - 1

#通過輸入的內容減一取得goods的索引

if shop_car.get(int_index) == none:

shop_car[int_index] = 1

else:

shop_car[int_index] = shop_car[int_index] + 1

#**********=讓使用者把商品加入到購物車**********==

elif choose.upper() == "n":

#結算#... == pass

#1.2 - 1.0 == 0.2 獲取到的是false 牛頓偏離法:乙個數學演算法導致的偏差

for f in shop_car:

fei_yong = fei_yong + shop_car[f] * goods[f]["price"]

if int(money) - fei_yong >= 0:

for k in shop_car:

print(f"你購買的商品有,單價是,數量")

else:

print("餘額不足,請刪除購物車商品")

for i,v in enumerate(shop_car): #列舉

print(f"")

str_del = int(input("請輸入你要刪除的商品"))

shop_car[str_del - 1] = shop_car[str_del - 1] - 1

if shop_car[str_del - 1] == 0:

shop_car.pop(str_del-1)

elif choose.upper() == "q":

#退出print(f"你的消費金額是:,餘額")

break

else:

print("輸入有誤,請重新輸入")

else:

#你給的假錢

print("請重新輸入")

葵花寶典 Flume

2 配置樣例 定義agent的名字 source channel sink a1.sources r1 a1.sinks k1 a1.channels c1 配置source 查閱官網 a1.sources.r1.type netcat a1.sources.r1.bind localhost a1...

葵花寶典 kafka

kafka是乙個分布式的基於發布 訂閱模式的訊息佇列,主要應用於大資料實時處理領域。producer 生產者,向kafka傳送資料 consumer 消費者,消費kafka內的資料 consumer group 消費者組,消費者組內的消費者負責消費不同分割槽的資料,乙個分割槽只能由乙個消費者消費,乙...

葵花寶典完全解析!

欲練神功,揮刀自宮。這是絕世神功 葵花寶典 的入門法則,聲稱要練這門神功的人必須先揮刀割掉自己的jj才能入門,殊為恐怖,於是早就了江湖上不少仁人志士為了練就神功,不惜捨棄人世間最重要的一項生活,忍痛割愛。然而,真的必須割麼?經過研究和思考,我發現乙個驚天秘密,其實中原的武林人士都對寶典的這句入門法則...