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 student.
Here is the create table statement from the distro code:
CREATE TABLE students (
id INTEGER PRIMARY KEY AUTOINCREMENT,
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 does then please check the tickmark.
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 INTO students (first, middle, last, house, birth) VALUES (?, ?, ?, ?, ?)", name, None, name,house, birth)
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 by a query is fixed. A column cannot be optionally selected. Assuming this is for the roster problem, a different approach would be to select middle in the ...
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:
This method commits the current transaction. If you don’t call this method, anything you did since the last call to commit() is not
visible from other ...
Use the template syntax, somewhat similar to printf format strings.
db.execute("INSERT INTO students (first, middle, last) VALUES (?, ?, ?)", lis, lis, lis)
The template syntax makes sure the values are passed in a safe way, encoded according to their type, so that none of the values end up being treated as SQL commands. Other solutions like ...
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 function (use print(lis()) to see it in action).
The correct syntax would be lis = row["name"].split().
Spoiler alert: program names the array lis, but is using ...