0

I cannot fix some problems in Pset8 because in my gradebook, Finance is still at 57%. Here are the errors that I have after I used check50:

  • :( logging in as registered user succceeds application raised an exception (rerun with --log for more details)
  • :| quote page has all required elements can't check until a frown turns upside down
  • :| quote handles invalid ticker symbol can't check until a frown turns upside down
  • :| quote handles blank ticker symbol can't check until a frown turns upside down
  • :| quote handles valid ticker symbol can't check until a frown turns upside down
  • :| buy page has all required elements can't check until a frown turns upside down
  • :| buy handles invalid ticker symbol can't check until a frown turns upside down
  • :| buy handles fractional, negative, and non-numeric shares can't check until a frown turns upside down
  • :| buy handles valid purchase can't check until a frown turns upside down
  • :| sell page has all required elements can't check until a frown turns upside down
  • :| sell handles invalid number of shares can't check until a frown turns upside down
  • :| sell handles valid sale can't check until a frown turns upside down

And here is my code, in application.py:

[code abridged for formatting, clarity and honor code]

@app.route("/")
@login_required
def index():
    """Show portfolio of stocks"""

    # get user information
    user = db.execute("SELECT * FROM users WHERE id = :id",
                      id=session["user_id"])[0]["cash"]
    user = round(user, 2)
    transactions = db.execute(
        "SELECT * FROM purchases WHERE id = :id", id=session["user_id"])

    # save in list
    stocks = []

    # get all data and put in dict
    for trans in transactions:
        symbol = trans["stock"]
        shares = trans["shares"]
        stock_data = lookup(symbol)

        temp_dict = {
            "symbol": symbol,
            "name": stock_data["name"],
            "shares": shares,
            "price": round(stock_data["price"], 2),
            "total": round(stock_data["price"] * shares, 2)
        }

        stocks.append(temp_dict)

    # get users current wealth
    total_money = round(user + sum([stock["total"] for stock in stocks]), 2)
return render_template("index.html", stocks=stocks, money=total_money, user=user)

I need some help to fix these, I NEED HELP BEFORE THE END OF 2019, OTHERWISE I WOULD HAVE TO START OVER AGAIN. PLEASE HELP ME

2
  • Did you rerun with --log for more details as suggested in the check50 output? What additional information does that contain? – DinoCoderSaurus Dec 17 '19 at 14:35
  • I don't know how to rerun with --log. Can you tell me how to do it? And here is the information it contains: Log sending POST request to /login exception raised in application: RuntimeError: (sqlite3.OperationalError) no such table: purchases\n[SQL: SELECT * FROM purchases WHERE id = 3]\n(Background on this error at: sqlalche.me/e/e3q8) – CorinTheGreat Dec 17 '19 at 22:42
0

According to the comments, index is producing this error:

Log sending POST request to /login 
exception raised in application: 
RuntimeError: (sqlite3.OperationalError)
 no such table: purchases\n[SQL: SELECT * FROM purchases WHERE id = 3]\n`

[NB: login does not query the purchases table directly, but redirects to "/", which does, so one can assume that is where the error occurs.]

That is a very clear and unambiguous message. The database that the app connects to does not have a table named purchases.

You need to add the purchases table to the database. sqlite is "tricky" in that it will create a new database if one is not found, as with sqlite3 finance.db. Make sure you execute sqlite3 (or command line phpliteadmin) from the directory that the database lives in (which should be the same directory as application.py).

These results might indicate that the code was submitted for grading but not tested locally. Conventional wisdom dictates that one has a reasonable expectation of success before submitting code for grading (or to a boss or a client!).

check50 cs50/problems/2019/x/finance --log will give additional info in the terminal window, essentially the same detail as in the results link.

3
  • I did make a purchases table in finance.db, but I still get the same results. JUST TELL ME HOW TO FIX THIS AND GET A PERCENTAGE ABOVE 57%, OTHERWISE I WONT GET TO WATCH STAR WARS THE RISE OF SKYWALKER!!! – CorinTheGreat Dec 19 '19 at 22:08
  • The fix is "make sure there is a table named purchases in the database that the app is accessing". Nothing more, nothing less. Maybe you spelled it different. – DinoCoderSaurus Dec 19 '19 at 22:37
  • Well there are some things that I found in finance.db. At the bottom, there is (Create new table on database 'finance') and (Create new view on database 'finance'). And on the top there is (Structure, SQL, Export, Import, and Vacuum). I don't know what these things do and what to type in these things. Which one am I supposed to do? – CorinTheGreat Dec 19 '19 at 22:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .