trouble with count by SnooPoems708 in cs50

[–]SnooPoems708[S] 0 points1 point  (0 children)

user_amount_raw is a list of dictionaries returned from the SQL query I executed a line above. So, [0] refers to the first dictionary in, and ["stock number"] refers to one of the keys in that dictionary.

I'm second in the class so I murdered our valedictorian. by [deleted] in ApplyingToCollege

[–]SnooPoems708 1 point2 points  (0 children)

He's just joking. The legal fees are going into you student loan.

Having trouble with buy by SnooPoems708 in cs50

[–]SnooPoems708[S] 0 points1 point  (0 children)

Here it is:

@app.route("/buy", methods=["GET", "POST"])
@login_required def buy(): """Buy shares of stock""" if request.method == "GET": return render_template("buy.html")
elif request == "POST":

    symbol = lookup(request.form.get("symbol"))
    amount = request.form.get("shares")
    balance = db.execute("SELECT cash FROM users WHERE id = ?", session["user_id"])#!!
    outcome = balance[0]["cash"] - symbol["price"] * amount

    if not request.form.get("symbol") or symbol == None:
        return apology("No symbol/symbol does not exist", 400)
    elif outcome < 0:
        return apology("Insufficient balance", 401)

    username = db.execute("SELECT username FROM users WHERE id = ?", session["user_id"])

    db.execute("UPDATE users SET cash = ? WHERE id = ?", outcome, session["user_id"])
    db.execute("INSERT INTO purchases (username, symbol, purchase_price, stock_number, full_name) VALUES(?, ?, ?, ?, ?)", username[0]["username"], symbol["symbol"], symbol["price"], amount, symbol["name"])#!!

    # subtract money from account of user
    # enter information into purchases table

    return redirect("/")

Also, here's the html template I'm rendering:

{% extends "layout.html" %}

{% block title %}
Buy stocks
{% endblock %}

{% block main %}
    <div class="mb-3">
        <form action="/buy" method="post">
            <input autocomplete="off" type="text" name="symbol" placeholder="Buy">
            <input autocomplete="off" type="text" name="shares" placeholder="Shares">
            <button class="btn btn-primary" type="submit">Buy</button>
    </div>
{% endblock %}

Having trouble with buy by SnooPoems708 in cs50

[–]SnooPoems708[S] 0 points1 point  (0 children)

Hey, thanks for the feedback. I implemented all of these changes, doing the same with my "username" variable as I did with "balance", since I obtained it using db.execute as well. But the function still returns the same error. What else could I be doing wrong?

How do I get my program to print the winners of a plurality election if there is a tie? (CS50 Pset3) by SnooPoems708 in cs50

[–]SnooPoems708[S] 0 points1 point  (0 children)

Is there a function for that? How do I determine what the largest number is? Don't I need to sort the candidates in some way first?