Hot answers tagged

2 votes
Accepted

Pset9 Finance Sell select menu

symbol is a list of dictionaries; that is what execute returns. Therefore the first result returns each dictionary in the template for symbol in symbol loop. Similarly, symbol[0]["symbol'} ...
user avatar
2 votes
Accepted

cs50 finance - RuntimeError: unsupported value: <function buy at 0x7f1c380cfd90>

buy in this sentence db.execute("INSERT INTO transactions(user_id, name, shares, price, type, symbol) VALUES(?, ?, ?, ?, ?, ?,)",user_id, item_name, shares, item_price, buy, symbol) refers ...
user avatar
2 votes
Accepted

PSET9 Finance: Check50 says Buy doesn't handle fractional/invalid shares, but when I try these things my page does reject them. Why check50 no like?

So my first question is, where does it come from? It's either bootstrap or the browser. check50 does not use the front end to make the API calls. Therefore any limits put on the html, while GREAT for ...
user avatar
1 vote
Accepted

PSET9 FINANCE SQLITE "no such column exists" while multiplying two columns to update a third

SQLite (or any other flavor of SQL) does not allow using column aliases in the same SELECT query.
user avatar
1 vote
Accepted

For finance, does anyone know why my page for selling stocks does not work?

Assume it is this line that produces error: quantity_owned = int((db.execute ("SELECT quantity FROM user_stocks WHERE user_id = ?"), session['user_id'])[0]) There is a ) in the wrong place. ...
user avatar
1 vote
Accepted

For finance, does anyone know why my page to buy stocks does not work?

I'm new to this, but am working on this PSET myself at the moment. Here's what I think the problem is (feel free to roast me if it's not! ;)): lookup returns a dictionary with 3 keys: 1.) name 2.) ...
user avatar
  • 38
1 vote

PSET 9: C$50 Finance. Why not <input type="number"> instead of text?

As you probably have already learned, problems must conform to the spec, full stop. I totally agree that the input should be validated in the HTML; it is better UI/UX. You could always run check50 to ...
user avatar
1 vote
Accepted

Lab 9: Birthdays - odd behaviour from delete button

Have you validated the HTML? (see Week 8 Lecture, starting at minute 54). The problem is identified in the spoiler, but you might want to take your generated HTML through the Direct Input tab at ...
user avatar
1 vote
Accepted

ValueError: UNIQUE constraint failed: on finance pset9, could someone point me in the right direction on which values should be UNIQUE from my table?

The error is on compras.id, which implies it is defined as UNIQUE. (Perhaps edit the compras schema into the question). The INSERT into compras is setting id to user_id, which would allow one purchase ...
user avatar
1 vote
Accepted

Check50 says buy allows fractional, negative numbers but it doesn't. Where am I going wrong?

While it is arguably better UI/UX to validate the input in the html, it does not fulfill the requirements of the buy spec: Require that a user input a number of shares, implemented as a text field ...
user avatar
1 vote
Accepted

Why does my lookup function keep returning "None"?

Since the quote spec calls for an element named "symbol", and this if not request.form.get("stock"): is apparently working, it looks like the element is not named properly in the ...
user avatar
1 vote

PSET9 / can't check until a frown turns upside down

Have a look at what your index renders if user buys 2 shares of something. I suspect it will show the price twice and not "total value for each holding". The usd function returns a string, ...
user avatar
1 vote
Accepted

I'm on pset9 right now and I'm running check50 on my code and getting :( logging in as registered user succeeds expected status code 200, but got 403

This hash = generate_password_hash("password") is a problem. It is hashing the string literal "password". (Try to login using "password" as the password; it should work). ...
user avatar
1 vote

check50 errors for "buy" and "sell"

If the symbol entered is invalid, this line price = search["price"] gives error "TypeError: 'NoneType' object is not subscriptable" because lookup returns None. Code will give ...
user avatar
1 vote
Accepted

Pset 9 Finance index function, current stock price not displaying correctly

The problem isn't lookup. The problem is portfolio. There are exactly two keys in the portfolio dictionary, "current_price" and "holding_total". They are set to the values in each ...
user avatar
1 vote

check50 on finance pset

It is much better UI/UX to add the constraints to the front end. Alas, check50 is verifying that the code performs as instructed in the spec. The same directive is given for buy and sell routes. From ...
user avatar
1 vote
Accepted

Pset9 Finance - How do I load the symbol into my input box on the Buy.html?

Add value = "{{ stocks }}" to the symbol input element in buy.html. There are some problems in the GET branch of the buy route: To retrieve values from a GET request, use request.args ...
user avatar
1 vote
Accepted

How to access the values returned by SELECT SUM

The problem is the double double-quotes. The first phrase is: "SELECT SUM(size) AS " the second phrase is: " FROM history WHERE id = ? AND symbol = ?" and Total is in no-man's land....
user avatar
1 vote
Accepted

Why is the portfolio not being displayed? I get not errors but nothing is being displayed. I am at a loss as to why I cannot display any stocks

You are iterating over a variable called holdings: {% for stock_holdings in holdings %} But you are not passing any such variable to the template: return render_template("index.html", ...
user avatar
  • 18.3k
1 vote
Accepted

Runtime Error Unsupported Value in pset9 Finance

From the doc for execute in CS50 Library for Python Returns for SELECT, a list of dict objects, each of which represents a row in the result set The argument to the INSERT query needs to be a ...
user avatar
1 vote
Accepted

pset9 buy function // buy handles invalid ticker symbol and handles valid purchase having error

Quote and stocks are one and the same. So you should keep only one of them. Your first error takes place at price = quote.get("price"). This line is correct but in the wrong place. Once you ...
user avatar
  • 957
1 vote
Accepted

CS50 Finance check50 problem in sell function, it works fine when i test it as well but idk what the problem is

The issue is that once you sell some stock, your profile_det (that you display on your index page) price values no longer have 2 decimal places. For example, if I buy 4 shares of a stock worth $28.00 ...
user avatar
  • 18.3k
1 vote
Accepted

pset9 finance // index function doesnt display the sum of the shares

This sql SELECT symbol, shares, price FROM transactions WHERE user_id = :user_id GROUP BY user_id, symbol uses a group by. But there is no aggregate function for the "grouping". Read up on ...
user avatar
1 vote
Accepted

pset9 finance // how can I check whether someone has registered

added_user = db.execute("INSERT INTO users (username, hash) VALUES(:username, :password_hash)", username=username, password_hash=password_hash) is going to fail if the username is taken, as ...
user avatar
  • 18.3k
1 vote
Accepted

pset9 // register function not registering user

The problem is simple. Your placeholder for hash in the sql insert statement is hash but then you have used hash_p instead of hash when assigning the value. Hope this helps. If it does then please ...
user avatar
  • 957

Only top scored, non community-wiki answers of a minimum length are eligible