简体   繁体   中英

Problems with CS50 - PSet7 Houses Submission

I have written the code for houses both import.py and roster.py and when I test them myself they both work and output exactly the output that the specification expects. Where I have trouble is when I submit it, even though my code works on my end it keeps telling me on check50 (when I submit it) that import.py produces no output at all. I have attached the results from check 50 to show what it says.

Thanks

check50 results

IMPORT.PY

import csv
import sys
from cs50 import SQL

if len(sys.argv) != 2:
    print("Usage: python import.py characters.csv")
    sys.exit(1)

db = SQL("sqlite:///students.db")

with open(sys.argv[1], "r") as characters:

    reader = csv.DictReader(characters, delimiter=",")

    for row in reader:

        name = row["name"]
        name_list = name.split()

        if len(name_list) == 2:
            first_name = name_list[0]
            last_name = name_list[1]
            db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES(?, ?, ?, ?, ?)",
                       first_name, None, last_name, row["house"], row["birth"])
        elif len(name_list) == 3:
            first_name = name_list[0]
            middle_name = name_list[1]
            last_name = name_list[2]
            db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES(?, ?, ?, ?, ?)",
                       first_name, middle_name, last_name, row["house"], row["birth"])

ROSTER.PY

import csv
import sys
from cs50 import SQL

if len(sys.argv) != 2:
    if sys.argv[1] != "Gryffindor" or sys.argv[1] != "Slytherin" or sys.argv[1] != "Hufflepuff" or sys.argv[1] != "Ravenclaw":
        print("Usage: python roster.py house")

db = SQL("sqlite:///students.db")

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

for row in house_list:
    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"]))

Apologies for missing the problem the first go round. When check50 runs there is already a students table in students.db, so the CREATE statement fails. Maybe it's too pedantic, but the spec has no instruction to create the table. As with all psets in this course, one should do and only do what the spec says.

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