第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

類型錯(cuò)誤:列表索引必須是整數(shù) - 處理金錢

類型錯(cuò)誤:列表索引必須是整數(shù) - 處理金錢

DIEA 2023-02-07 10:41:26
我正在嘗試“執(zhí)行”股票的(假)買單。cash = cashcheck["cash"]我在該行遇到錯(cuò)誤。它說(shuō)索引必須是整數(shù),但我們談?wù)摰氖清X,所以它不能是一個(gè)整數(shù),因?yàn)樯婕靶?shù)......我認(rèn)為。非常感謝您的幫助!代碼:@app.route("/buy", methods=["GET", "POST"])@login_requireddef buy():    """Buy shares of stock"""    if request.method == "GET":        return render_template("/buy.html")    else:        # collect user input - symbol        symbol = request.form.get("symbol").upper()        # if input is blank or symbol doesn't exist, return apology        if not symbol:            return apology("You must enter a stock symbol.", 300)        # collect user input - # of shares        shares = int(request.form.get("shares"))        # if blank or not a positive integer, return apology        if not shares:            return apology("Enter a valid number of shares.", 300)        # pull current price info from API        quote = lookup(symbol)        shareprice = quote["price"]        totalprice = shareprice * shares        # check users table to see how much cash user has        cashcheck = db.execute("SELECT cash FROM users WHERE id = :userid", userid = session["user_id"])        cash = cashcheck["cash"]        if cash >= totalprice:            # in transactions table, insert userID, symbol, shares, shareprice, and totalprice            # transID should be autogenerated and autoincremented.  date is also autofilled by SQLite.            db.execute("INSERT INTO transactions (userID, symbol, shares, shareprice, totalprice) VALUES (:userid, :symbol, :shares, :shareprice, :totalprice)",            userid=session["user_id"], symbol=symbol, shares=shares, shareprice=shareprice, totalprice=totalprice)            cash = cash - totalprice            # update cash balance            db.execute("UPDATE users SET cash = :cash WHERE id = :userid", userid = session["user_id"])            #return index            return ("/")        else:            # else, return apology (not enough cash)            return apology("Not enough cash balance to make execute this order.", 300)
查看完整描述

1 回答

?
胡說(shuō)叔叔

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超8個(gè)贊

cashcheck是與查詢匹配的行的列表。

如果您只希望匹配一行,請(qǐng)使用cashcheck[0]["cash"].


查看完整回答
反對(duì) 回復(fù) 2023-02-07
  • 1 回答
  • 0 關(guān)注
  • 136 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)