Hot answers tagged

7

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


5

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: [ [ { "accuracy": 4, "admin_code1": "MA", (notice the two [) that is the problem. It should show one list like this: [ { "accuracy": 4, "...


5

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: https://stackoverflow.com/questions/42789666/pylint-error-message-on-cloud-9-cs50


4

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 import cs50 as cs h= cs.get_int()


4

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/flask/issues/2549, and duplicate https://github.com/pallets/flask/issues/2599), and is fixed in current release, so let's hope we get an updated version soon (as ...


3

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)] would for example create a list of square numbers, from 0 to 100. tweet["text"] indicates that tweet (an element of tweets) is a dict, and has a property "...


3

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 journey in earnest with CS50 in August 2015 and currently teach CS50 AP. I've also explored a handful of different MOOCs: Nand to Tetris, Programming Languages, and ...


3

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 fixed the first line: print("s: ", end="" ) UPDATE: I've logged back in this morning to find the invalid syntax flag is back even on my updated code. At ...


3

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 how many times (eg for (i = 0; i < strlen(somestring); i++). The for stock in stocks notation is "syntactic sugar"; it knows how long stocks is, so it does ...


3

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 inserted contains an autoincrementing PRIMARY KEY, then execute returns the value of the newly inserted row’s primary key. If users.id is not autoincrement ...


2

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 == blank || password is blank) { // return apology; } if (password == again_password) { // insert finance row } printf("message"); ...


2

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 having us do C. Python is "easy" in the sense that it uses a lot of English or human-readable words. Take a for-loop, for example: for letter in word // do ...


2

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 achieved - just change input() to raw_input() and remove the brackets around print


2

Check your spelling! Sometimes it's the simple things ;)


2

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 moved the () just to the end my code worked. Hope this helps.


2

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 in C. That's where chr comes in.


2

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 open(negatives) as negative: You could condense the conditionals: for line in negative: if not line.startswith((";", " ")): self.negatives....


2

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.


2

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, shares FROM portfolio WHERE id = :id" Now iterating over a simple list of fruits ( eg: fruits = ['apples', 'oranges', 'pears', 'apricots'] ) can be done simply ...


2

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", function(). That's not the correct syntax to add a listener to a marker (extraneous argument). Review the api doc here. Once you get those things sorted, ...


2

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 (finally) rendered by the browser, it is "recognized" as html. rather than writing part of the program in python and part in JavaScript, have ...


2

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.symbol should not be quoted nor escaped with braces. (the quotes make it a literal; the braces are only used to escape the objects from html). An a element ...


2

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 with two blank lines. Method definitions inside a class are surrounded by a single blank line. Additionally, Python does have data types, you just don't have ...


2

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 means when matrix[0][0] is dealt with, i and j both get set to -1, which will be out of range. Perhaps you should be using None instead of Substituted for the ...


2

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 the // operator (integer division operator).


2

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 the else path triggers. i is a bad choice for a variable name, and if it is used as such, it usually means an integer, not a string as in your code. For a ...


2

One thing first, and has higher precedence than or. A or B and C is same as A or (B and C). Keep that in mind when combining the two. In Python, pretty much like in C, firstTwo == 51 or 52 or 53 or 54 or 55 is interpreted as (firstTwo == 51) or (52) or (53) or (54) or (55), five expressions combined with or. As all but the first (which may or may not) are ...


2

In the first version, the list comprehension is evaluated with the current value of returnlist, which you likely set to an empty list. It does not change over time. Only after the new list has been generated, it is assigned to variable returnlist, replacing whichever value the variable had (so likely replacing your empty list). Which means you can't check ...


2

JavaScript $.get is asynchronous. It triggers an HTTP request and returns. The code meant to prevent submission runs after submission is processed, and therefore can't prevent it. The preventDefault has to go into the submit handler, not the $.get callback, and would be called each time you try to submit, cancelling the submit attempt. Inside the get ...


2

Two things. First, and foremost, your program will keep going after it finds the password because your break only breaks out of the inner for loop. After finding the password, you should exit immediately. Second, printing the crypted possibilities will really slow down the program. And it masked the first problem, since your "Found!" was printed in ...


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