Hot answers tagged

3 votes
Accepted

pset7 Houses get 17% submit

The pset requires a table names students (plural). That is how the distro database is configured. It looks like this program is looking for a table named student singular, based on this INSERT INTO ...
2 votes
Accepted

PSET 7, failing on Luna Lovegood test case even though output looks the same as expected output

The None keyword is used to define a null value, or no value at all. When you put none in ' ' , it becomes a string. Remove the ' ' and it should work fine. Have a great day!.
  • 371
1 vote
Accepted

pset 7 houses passes check 50 but shows the names 4 times

Just check your database. I guess the data has been imported 4 times because of which each name has been printed 4 times. There is no real problem with any of your code. Hope this helps you. If it ...
  • 992
1 vote
Accepted

Pset 7 Houses: Import seems to work but check50 doesn´t agree

This with open("characters.csv", "r") is a problem. Why take an argument and not use it? Don't hard code the file name.
1 vote

In students its printing all the data correctly but when I try to insert it into db its showing this funny error

I just figured it out on the INSERT INTO am inserting variables so I have to format the string or in a better way use the "?" place holder so avoid SQL injections db.execute("INSERT ...
1 vote
Accepted

Why updating a dictionary is not working?

Maybe a typo? == is not the set operator, it is the relational operator. This row['middle'] == "" evaluates to False; it does not change the value of row['middle'].
1 vote
Accepted

PSET 7 HOUSES - Syntax error on case function

The CASE is the fourth column in the select, so it needs a , after birth. That will fix the syntax error. It may not, however, give you the result you are looking for :) The number of columns returned ...
1 vote
Accepted

CS50 Houses : Output is correct in my console but error in check50

Fixed the errors import.py : The name check for characters.csv was too specific. Needed to check only for file format of .csv roster.py : Extra space after each line Thanks for your help :D
1 vote

Houses ~ Import.py - Nothing being inserted into students.db

Since program uses the sqlite3 python interface (not the CS50 SQL interface), any changes to the database need to be committed in order to persist. From the python sqlite interface doc: commit() ...
1 vote
Accepted

Reason for error pset7

Use the template syntax, somewhat similar to printf format strings. db.execute("INSERT INTO students (first, middle, last) VALUES (?, ?, ?)", lis[0], lis[1], lis[2]) The template syntax makes sure ...
  • 20.7k
1 vote
Accepted

Reason for error pset7 houses

Assume error comes at if (len(lis) == 2): (there are two "len" in the program). The problem is here lis = row["name"].split, because it is not calling the split function. It is declaring lis a ...
1 vote
Accepted

pset7 houses: dict to SQL

executemany is included in the python sqlite3 library, but not in the cs50 SQL library. One option would be to iterate over the dict and insert one row at a time.

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