4
votes
Accepted
pset2 caesar converting from ascii to alphabetical
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)
...
3
votes
PSET 7 Index.php Fatal error: Call to undefined function query()
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
votes
Accepted
Pset7 - index() ValueError: could not convert string to float
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. ...
2
votes
Accepted
pset 7 index - how to get total value of shares held and add to cash balance
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
votes
Accepted
pset7 index.html Jinja
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 ...
2
votes
Accepted
Finance index function does not return lookup value in index.html
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 ...
1
vote
Accepted
Finance index.html is not rendering values from my index function
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
vote
Accepted
Runtime error in pset4
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 ...
1
vote
Finance Portfolio (index) I can't go on. Need to take to HTML the actual price and total of stock
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 ...
1
vote
Accepted
Finance - Error with Index
--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 ...
1
vote
Accepted
Pset8 Finance - SELECT is blank
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
vote
Accepted
pset7 index - can't get anything from the db to html
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 ...
1
vote
Jinja template exception: "jinja2.exceptions.TemplateSyntaxError"
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....
1
vote
pset6 server fails check50
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 ...
1
vote
pset6 server fails check50
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
vote
Accepted
pset7 finance: index not working after register
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 ...
1
vote
Pset7 index RuntimeError object has no attribute name
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 ...
1
vote
Accepted
TypeErrors and variable storage questions
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 ...
1
vote
pset7 finance/index problem updating values in table
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 ...
1
vote
Accepted
pset7 finance/index problem updating values in table
"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 ...
1
vote
pset7 index table not showing all values
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 ...
1
vote
Accepted
why can't I even log in now ? pset7
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", \
...
1
vote
Accepted
pset7 "index" - using SQL SUM adds a parenthesis to returned dict strings
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....
1
vote
pset7 index TypeError: 'NoneType' object is not subscriptable
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 ...
1
vote
Accepted
pset2 Initials - negative index
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 ...
1
vote
Accepted
Pupose of index in speller.c
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 ...
1
vote
CS50 Pset7: rows inside the for loop are not showing up in index.html
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 {% ...
1
vote
Accepted
CS50 Pset7: rows inside the for loop are not showing up in index.html
Try using the dot operator instead. {{stock.stock}} and{{stock.total_shares}}
1
vote
Accepted
CS50 Pset7: rows inside the for loop aren't showing up in index.html
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
vote
Accepted
PSET 2 - Vigenere's cipher: Index of key's current letter not working properly
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible