简体   繁体   中英

Problem houses of pset7, cs50 does not qualify check tests

Problem houses of pset7, cs50. The output of my program is as per requirement but my code doesn't qualify 5 out of 6 tests. I have tried a lot but couldn't find the mistake. Please help me out. import.py

import sys
import cs50
import csv
if (len(sys.argv) !=2):
    print("Error: Incorrect Command-line Arguments")
    exit (1)
db =cs50.SQL("sqlite:///students.db")
db.execute ("DROP TABLE students")
db.execute ("CREATE TABLE IF NOT EXISTS students (first TEXT,middle TEXT,last TEXT,house TEXT,birth NUMERIC)")
with open ("characters.csv", "r") as characters:
    reader = csv.DictReader(characters,delimiter = ",")
    for row in reader:
        name = row["name"]
        name_list = name.split()
        if (len(name_list) == 3):
            first = name_list[0]
            middle = name_list[1]
            last = name_list[2]
        elif (len(name_list) == 2):
            first = name_list[0]
            middle = None
            last  = name_list[1]
        house = row["house"]
        birth = int (row["birth"])
        db.execute("INSERT INTO students (first,middle,last,house,birth) VALUES (?,?,?,?,?)",first,middle,last,house,birth)

roster.py

import sys
import cs50
import csv
import sqlite3
if (len(sys.argv) !=2):
    print("Error: Incorrect Command-line Arguments")
    exit (1)
user_house = sys.argv[1]
db = cs50.SQL("sqlite:///students.db")
list_dicts = db.execute("SELECT first, middle, last, birth FROM students WHERE house = (?) ORDER BY last, first", (user_house)) 
for row in list_dicts:
    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"]))

Your students table does not match the schema supplied in the distro code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM