reading the specification of 'buy' for pset7, which says the following:

buy Complete the implementation of buy in such a way that it enables a user to buy stocks.

Require that a user input a stock’s symbol, implemented as a text field whose name is symbol. Render an apology if the input is blank or the symbol does not exist (as per the return value of lookup).

Require that a user input a number of shares, implemented as a text field whose name is shares. Render an apology if the input is not a positive integer.

Submit the user’s input via POST to /buy.

Odds are you’ll want to call lookup to look up a stock’s current price.

Odds are you’ll want to SELECT how much cash the user currently has in users.

Add one or more new tables to finance.db via which to keep track of the purchase. Store enough information so that you know who bought what at what price and when.

Use appropriate SQLite types.

Define UNIQUE indexes on any fields that should be unique.

Define (non-UNIQUE) indexes on any fields via which you will search (as via SELECT with WHERE).

Render an apology, without completing a purchase, if the user cannot afford the number of shares at the current price.

You don’t need to worry about race conditions (or use transactions).

Once you’ve implemented buy correctly, you should be able to see users' purchases in your new table(s) via phpLiteAdmin or sqlite3.

There is nothing in the spec saying to output the purchase price to the user. So that's fine, check50 tells me I should be doing that. So I added another html page "bought.html" and pass it in the sale price (price per share * number of shares) via render_template, which is returned from my buy function after a successful purchase. I've test this and it works. However, I am still failing this check. To further complicate things, it is working for 1 of the stocks (it successfully finds the value "112.00"), but apparently not another. Check50 doesn't tell me what input is being used when the check is failed (what stock symbol/number of shares being bought), which would be helpful for my own debugging.

:( buy handles valid purchase expected to find "9,888.00" in page, but it wasn't found

Log sending POST request to /login sending POST request to /buy

checking that "112.00" is in page
checking that "9,888.00" is in page

[code snipped to avoid spoilers]

1 Answer 1


There is nothing in the spec saying to output the purchase price to the user.

That is because such a page is not required.

check50 is parsing your index.html page after it makes one purchase, so it should find the current value of those shares 112.00 and the updated value of cash (10000-112) 9,888.00

If I had to guess, I'd say that you aren't formatting your numbers in the jinja template to be formatted using usd like {{value | usd}}

One more answer: https://stackoverflow.com/a/77706367/20806031

  • Thank you so much, you are correct! Just got a little confused.
    – JohnWick
    Mar 15, 2018 at 22:00
  • If you get the chance, could you take a look at another problem I am having with this pset? I want to rip my hair out :\ cs50.stackexchange.com/questions/28571/…
    – JohnWick
    Mar 15, 2018 at 23:37
  • how did you solved this ?? @JohnWick Oct 11, 2021 at 15:00

You must log in to answer this question.

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