pset7,cs50的问题房子不符合检查测试的条件

时间:2020-06-06 14:03:50

标签: python sqlite

pset7,cs50的问题之家。我的程序的输出是按要求的,但是我的代码没有合格6个测试中的5个。我已经尝试了很多,但是找不到错误。请帮帮我。 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"]))

1 个答案:

答案 0 :(得分:0)

您的学生表与发行代码中提供的架构不匹配。