0

My code run right and My output same they output but after submitted get 17% why

//import.py
    from sys import argv, exit
    import cs50
    import csv

    if len(argv) != 2:
        print("missing command-line argument")
        exit(1)

    open(f"students.db","w").close()
    db = cs50.SQL("sqlite:///students.db")

    db.execute("CREATE TABLE student (id INTEGER PRIMARY KEY AUTOINCREMENT, first TEXT, middle TEXT, last  TEXT, house TEXT, birth NUMERIC)")

    with open(argv[1],"r") as titles:
        reader = csv.DictReader(titles)

        for row in reader:
            name = row["name"]
            house = row["house"]
            birth = int(row["birth"])
            part = name.split();
            if(len(part) == 3):
                db.execute("INSERT INTO student(first,middle,last,house,birth) VALUES (?,?,?,?,?)",
                          part[0],part[1],part[2],house,birth)
            elif (len(part) == 2):
                db.execute("INSERT INTO student(first,last,house,birth) VALUES (?,?,?,?)",
                          part[0],part[1],house,birth)

     //roster.py

        from sys import argv, exit
    import cs50

    if len(argv) != 2:
        print("missing command-line argument")
        exit(1)

    db = cs50.SQL("sqlite:///students.db")
    house = argv[1]

    rows = db.execute("SELECT first,middle,last,birth FROM student WHERE house = ? ORDER BY last,first",argv[1])

    for row in rows:
        if(row["middle"]== None):
            print(row["first"]+" "+row["last"]+", born "+str(row["birth"]))
        else:
            print(row["first"]+" "+row["middle"]+" "+row["last"]+", born "+str(row["birth"]))

My output right similar they want errors errors

3

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,
    first VARCHAR(255),
    middle VARCHAR(255),
    last VARCHAR(255),
    house VARCHAR(10),
    birth INTEGER
)
1
  • This was so helpful, thanks!!
    – Mary Clare
    Jul 20 '20 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .