cs50 :( 购买处理有效购买,预计在页面中找到“112.00”,但没有找到

问题描述 投票:0回答:1

我出现了一个问题,但我不知道它来自哪里。我将所有内容都转换为浮动,但它不起作用。我试图寻找解决方案,但找不到。仅限此功能。

:( buy 处理有效购买 预计在页面中找到“112.00”,但没有找到

我的代码是否有人可以看到它并告诉我如何修复

代码{

def buy():

if request.method == "POST":
    symbol = request.form.get("symbol").upper()
    shares = request.form.get("shares")

    if not symbol:
        return apology("must provide symbol", 400)
    elif not shares or not shares.isdigit() or int(shares) <= 0:
        return apology("must provide a positive integer number of shares", 400)

    quote = lookup(symbol)
    if quote is None:
        return apology("symbol not found", 400)

    price = quote["price"]
    total_cost = int(shares) * price
    cash = db.execute("SELECT cash FROM users WHERE id = :user_id", user_id=session["user_id"])[0]["cash"]

    if cash < total_cost:
        return apology("not enough cash", 400)

    # Update users table
    db.execute("UPDATE users SET cash = cash - :total_cost WHERE id = :user_id",
                total_cost=total_cost, user_id=session["user_id"])

    # Add the purchase to the history table
    db.execute("INSERT INTO transactions (user_id, symbol, shares, price) VALUES (:user_id, :symbol, :shares, :price)",
                user_id=session["user_id"], symbol=symbol, shares=shares, price=price)

    flash(f"Bought {shares} shares of {symbol} for {usd(total_cost)}!")
    return redirect("/")
else:
    return render_template("buy.html")

}

我不知道我尝试检查代码但仍然不起作用

cs50 finance
1个回答
0
投票

在index.html中只是让他想显示总价值和他的我的代码

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.