Hot answers tagged

4

Your formula is correct as well as the understanding of the formula, only that you are mixing two things in a wrong way, look carefully at the following expression: ((('s[i]' - 97) + n) % 26) + 97) What is s[i], and what is 's[i]'? I have to say that it is the first time that I encounter this situation, probably 's[i]' is interpreted by the compiler as a ...


3

query() is defined in the CS50 PHP library, so you need to put CS50::query(whatever) instead of just query. PHP isn't quite as smart with included libraries as C is apparently. :)


2

This will happen if you store cash in users table with usd format. The usd function should only be used for displaying. It turns it's argument into a string. That is likely what is causing the error. cash should be stored in the database as a number, not formatted with usd.


2

You could add an accumulator in the for line loop (like tot_val += line["value_shares"], and then make quote_cash a list where quote_cash[0] is the cash and quote_cash[1] is shares value.


2

Instead of working with two arrays (portfolio and quote), consider adding a key/value pair to the portfolio array for the value of the holding. In index, where you iterate over portfolio you could try something like: lookup the stock, then add a key to line with the extended price: line["value"] = price (from lookup) * shares (from line). Everything you need ...


1

Each dict in portfolio contains 3 keys as returned from the execute. There is no key current_price, so the html does not render anything for that column. If the key gets created in the for loop in index, then it will be available to the html. Something like record['current_price'] = share['price'].


1

The problem is in the index function. The html is expecting a list named portfolio, but alas no such list is sent along with the render_template.


1

Question: When this code calculates blur values for each pixel, are those values stored in a temporary array, or stored back in the original image array as it goes along? Every pixel's blurred values must be calculated on the original values in the surrounding cells. If the cells are updated, then the cells that follow will be calculated on blurred values, ...


1

Suggest you add the desired fields to the portfolio dicts. In the for row in portfolio: loop, something like row['name'] = share['name'] for example. When portfolio is sent to the html, each row will be self-contained.


1

--AFTER EDIT-- This line change = lookup(stocks) is a problem. execute returns a list of dictionaries, therefore stocks is a dictionary, therefore lookup is choking, I mean, producing the error message. This line shares= float(change["shares"]) is a problem, since lookup does not return a key named "shares". I can't say for sure if that ...


1

SELECT ticker, SUM(shares) FROM activity WHERE id = 6 GROUP BY ticker Are you sure you want to get rows with id = 6? I'd expect that you want user_id = 6.


1

Sorted! I just realised I kept refreshing the redirect from 'buy' instead of going directly to 'index' - for some reason the redirect doesn't use the code in index - I'll sort that later but for now I can at least start on getting the right data in...!!!


1

holdings in your python script is a dict. The {% for holding in holdings %} in the jinja template suggests a list of dicts instead. {% holding.total + holding.cash %} is the part crashing your script. Use {{ }} instead of {% %} for those.


1

First of all, WOW: your code is awesome. I took LOOKUP on the side and I could not see any obvious errors. I did find some behaviors on PARSE you might find useful. This is how I debugged your function: I have this program called parse.c where I copy and pasted your function: #include <stdio.h> #include <string.h> #include <strings.h> ...


1

There are some problems that are quick to see. They are most likely not all the problems in play here. parse The server1 failure probably stems from here strncpy(request, req_pos, (v_pos - req_pos - 1)); From man strncpy: The strncpy() function is similar, except that at most n bytes of src are copied. Warning: If there is no null byte ...


1

There's a problem here session["user_id"] = "id". "id" is a string literal, not users.id from the database. Remember this Hint from the spec: If str is an INSERT, and the table into which data was inserted contains an autoincrementing PRIMARY KEY, then execute returns the value of the newly inserted row’s primary key. NB: The "AUTOINCREMENT" does ...


1

Ignore that last error, it's caused by the error above. You should not store stocks in users table, but in another table. Error message suggests that even though you specify "users" table, it does not have these fields. Note that cash in your case is a list with one element, a dict with a property "cash". So the number you meant would not be cash, but cash[...


1

Could someone please explain what is actually getting stored in ledger? Do you mean this ledger SELECT company, SUM(number_purchased) AS total_shares FROM ledger WHERE...... You can view the table structure in phpLiteAdmin (or sqlite3) to see what is stored in ledger table. Rows are (probably) created in the buy function, so review that to get more ...


1

Welcome to the forum! None of the update statements in the debugger view updated any rows. None of them found a matching symbol in the test table. Notice, test.symbol in the database is goog, but the WHERE clause specifies GOOG. From the Hints section in the spec: If str is a DELETE or an UPDATE, then execute returns the number of rows deleted or ...


1

"It did exactly what I said, but not what I wanted!" ;-) db.execute("UPDATE test SET price=:price, total=:total WHERE symbol=:symbol", price=price, total=total, symbol=quote['symbol']) This SQL code says to update the price and total for EVERY row in the table that has the given symbol. So, any row with APPL gets updated. (Not sure what's going on with ...


1

The variables/members/attributes referenced in index.html don't match the ones in the list you pass, there is no symbol, but stock. grandTotal is not same as grandtotal. You don't seem to use valbystock.


1

Here you replace the string with a dict: symbol = lookup(symbol) here you use symbol: db.execute("UPDATE log SET price=:price, \ total=:total WHERE id=:id AND symbol=:symbol", \ price=usd(symbol["price"]), \ total=usd(total1), id=session["user_id"], symbol=symbol) Either use another variable name (which ...


1

You can use AS to rename a field, this is especially useful if you join multiple tables and return fields from several of them, or when using aggregate functions as you do here. Like "SELECT buy.stock_code AS symbol, SUM(buy.value) AS value, SUM(buy.shares) AS shares FROM buy ... Alternatively, you can drop the AS, but if I remember correctly, for some ...


1

see how you use cash: cash = cash[0]["cash"] however with holding you do the following: symbol = holding["symbol"] shares = holding["shares"] the problem is in holding, which is an array, to iterate properly over holding we must do a little trick in the for loop. i = 0 for holding in holdings: symbol = holding[i]["symbol"] shares = holding[i]["...


1

Have you tried? if (i == 0 || name[i] == 32) { printf("%c", toupper(name[i + 1])); } In the most comfortable edition we assume that the user enters the name correctly and that the space is not the last place, it is not necessary to check the limits of the array, for now should suffice with this code. EDIT: I was thinking less comfortable, you're right....


1

Index is used to keep track of which character is being iterated over in the word to spell checked. It is also used to verify that the word being spell-checked is a word meeting the standard of, a certain length. i.e not longer than the longest word in the English Language. Index is used wherever we are dealing with words to be spell-checked, checking if a ...


1

There is no stocks array being sent return render_template("index.html", cash=str(round(cash[0]["cash"], 2)), total_worth=total_asset). Therefore, stocks is an empty array in the html. Therefore {% for stock in stocks %} executes 0 times.


1

Try using the dot operator instead. {{stock.stock}} and{{stock.total_shares}}


1

lookup() in helpers.py is not available to jinja. It should be called in index. But that would give a big fat exception. Suspect index is sending an empty list to stocks argument.


1

The index of the plain text and the index of the key must be independent of each other. When a non-alpha is processed, the plaintext key is incremented but the index of the key MUST NOT be incremented. In the code above, both are based on i. Does this look familiar? Create an int var to be used as the index for the key, let's say j. When a letter is ...


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