简体   繁体   English

pset7、cs50 的问题房屋不合格检查测试

[英]Problem houses of pset7, cs50 does not qualify check tests

Problem houses of pset7, cs50. pset7、cs50 的问题房屋。 The output of my program is as per requirement but my code doesn't qualify 5 out of 6 tests.我的程序的 output 符合要求,但我的代码不符合 6 个测试中的 5 个。 I have tried a lot but couldn't find the mistake.我已经尝试了很多,但找不到错误。 Please help me out.请帮帮我。 import.py导入.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名册.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.您的学生表与发行版代码中提供的架构不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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