Hot answers tagged

7 votes
Accepted

IndexError in initial state of pset6 Sentiments

This command pip3 install --user -r requirements.txt --upgrade solves the problem according to this post on reddit (and the comments here :).
user avatar
6 votes

Instance of 'scoped_session' has no 'commit' member

They are warnings from pylint. You can tell pylint to ignore that error by create file .pylintrc in your folder with contains: ignored-classes=SQLObject,Registrant,scoped_session reference link: ...
user avatar
  • 61
5 votes
Accepted

Pset8: typeahead not working in js file※i am using python for solving this problem set

One common cause of this problem is search returning a nested list instead of a list. A quick way to detect this is doing a call to search?q=021. If the result shows nested lists: [ [ { "...
user avatar
4 votes
Accepted

Why can't I use get_int in python

In python, if you want to use a function from an imported library, you have to somehow tell Python that you are going to get that function from which library. I would do: h= cs50.get_int() or ...
user avatar
  • 74
4 votes
Accepted

jsonify not working when I add this line of code <<db = SQL("sqlite:///mashup.db")>> to application.py

So it seems the workaround solution was to add app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False somewhere after the app = Flask(__name__) The issue has been reported (https://github.com/pallets/...
user avatar
  • 20.7k
3 votes
Accepted

Python. Can't understand this code

The [expression_using_X for X in Y] is evaluating expression_using_X for every X being an element of Y, and the [] make that list of expression values a Python list. squares = [x**2 for x in range(11)...
user avatar
  • 20.7k
3 votes
Accepted

C vs Python in MOOCs?

You can find the "official" answer from David Malan himself here: "Why does CS50 at Harvard use C as its primary language?" A few words from my own perspective... I began my formal programming ...
user avatar
  • 1,424
3 votes
Accepted

python invalid syntax end=""

I added a space in there and it took the flag away. The rest of the print lines without the space are not flag. I'm wondering if this is a bug with the IDE or am I not understanding something? This ...
user avatar
  • 41
3 votes
Accepted

Pset7, Index: How to use loops in Python and Jinja?

The for loop is working and is displaying exactly the data it has. And it technically (theoretically?) is identical to a for loop in C. Perform this code x times. Syntactically, you (normally) tell C ...
user avatar
3 votes
Accepted

How to fix KeyError: 'id' error in pset7 register?

True. row has no element id because row only contains the columns selected. But do you really need to do another SELECT? From the spec Hints: If str is an INSERT, and the table into which data was ...
user avatar
3 votes
Accepted

Why can't I print the entire string from the read file?

I guess you meant print(dna[i:i+len("AGATC")]). In Python, if the end of the substring is before the beginning, the substring is empty, so you are printing a bunch of empty strings.
user avatar
  • 20.7k
2 votes
Accepted

For register in pset 7 where I am doing wrong?

It looks like this function will always print "Both passwords don't match" and redirect to register.html (unless username or password is blank). In pseudo-C this routine would look like: if (username ...
user avatar
2 votes

Problem with cs50 python module - folder restricted

I had the same problem as you describe in your post. As @Rushil mentioned in his comment, it can be sorted by renaming the file you have named "string.py" in your directory. Seems there is a conflict ...
user avatar
  • 23
2 votes

C vs Python in MOOCs?

I've noticed that many universities (including MIT) seem to prefer Python as a starting language. That's true! I myself prefer Python as a starting language. However, I can understand why CS50 is ...
user avatar
2 votes
Accepted

Make the code better - analyzer.py pset6

positives and negatives are file names sent to the function, so instead of hardcoding the file name like this with open("negative-words.txt") as negative:, use the variable name like this with ...
user avatar
2 votes
Accepted

Running python scripts in the cs50 appliance

The thing wrong with this code is you're using Python 3. When trying to run it on Python 2.7 on windows, it raises the same error, so you should try porting it to the earlier version. This is easily ...
user avatar
  • 36
2 votes
Accepted

Pset6 2017 - 'str' object has no attribute 'isaplha' - caesar.py

Check your spelling! Sometimes it's the simple things ;)
user avatar
2 votes

Caesar (python) error

I think the problem is that you have a () around the if(plaintext[i].isalpha): when it should be if plaintext[i].isaplha(), and the same for isupper and islower. I had the same problem but when I ...
user avatar
  • 27
2 votes

Caesar (python) error

From the Hints section of the spec: You might find chr and/or ord of help. Python does not treat plaintext[i] the same way that C does. That's where ord comes in. Python int is more like atoi ...
user avatar
2 votes
Accepted

How to use multiple "WHERE" while updating table in sqlite

You can use the AND logic keyword, as below: UPDATE table SET field1=value1 WHERE field2=value2 AND field3=value3 There is also an OR keyword.
user avatar
2 votes

Pset7 - Finance: Cannot figure out how to loop through values in list/dict in order to display results in rows in html table

What is going to be stored into your holdings value is "A list of dictionaries", where each list item will be one stock. i.e each list item will correspond to each row of your query: "SELECT stock, ...
user avatar
  • 123
2 votes
Accepted

Pset7 buy - RuntimeError sqlite3.OperationalError near transaction

transaction is a sqlite reserved word. You'll need to escape the column name with quotes (eg 'transaction') or create the table again and rename the column.
user avatar
2 votes
Accepted

Struggle passing values from Python to HTML via Flask

From the flask doc (Rendering Templates): To render a template you can use the render_template() method. All you have to do is provide the name of the template and the variables you want to pass ...
user avatar
2 votes
Accepted

CS50 Pset8: Info Window Not Showing

One problem is this syntax markers += marker;. That does not add an element to an array in js. The array method push adds elements to an array. Another problem is here marker.addListener(map, "click"...
user avatar
2 votes
Accepted

CS50 Pset8: Final Questions before Wrap-Up

How does the computer recognize that those few lines inside a JavaScript file is actually html and not JavaScript codes? It doesn't. It's not javascript or html to the function, it's data. When it is (...
user avatar
2 votes
Accepted

How to pre-populate sell() and buy() forms from index - Pset7

The "something like" syntax in this call for the href attribute was wrong and has been corrected. It is more something like href="{{ url_for('buy', symbol=stock.symbol ) }}". stock....
user avatar
2 votes
Accepted

greedy.py returning integer variable ending with .0 even w/ conversion from float to int() & round()

First a couple of stylistic problems I noticed. Per PEP8, which is the style guide for Python, and more specifically the BlankLines part, you should: Surround top-level function and class definitions ...
user avatar
  • 7,326
2 votes
Accepted

PSET6 Similarities (More) 500 Internal Server Error

except for the first element, which is supposed to have no operation, but I gave it an Operation.SUBSTITUTED And this is probably the problem, since that operation subtracts 1 from i and j, which ...
user avatar
  • 18.3k
2 votes
Accepted

I have problems applying Credit in python

If you were to print(warehouse) after this line warehouse = ((c_number / 10)%10)*2 you'd discover that it returns a floating point number. Python doesn't do integer division like C unless you use ...
user avatar
  • 18.3k
2 votes
Accepted

Python Caesar not working for mix case etc

Multiple things. if plaintext.isupper(): you meant i.isupper(). plaintext.isupper() would check whether the whole string is upper-case, which it is not, but it also isn't completely lower-case, so ...
user avatar
  • 20.7k

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