I have a really strange problem here: both import and rooster passes every check in check 50, but if I run Rooster the names on every house appear 4 times. I have no clue about why this is happening, here is my code:
Import:
from sys import exit
from sys import argv
from cs50 import SQL
import csv
import cs50
import sqlite3
if len(argv) != 2:
print("missing command-line argument")
exit(1)
db = SQL("sqlite:///students.db")
with open(argv[1], "r") as characters:
reader = csv.DictReader(characters)
for row in reader:
name = row["name"]
house = row["house"]
birth = int(row["birth"])
part = name.split()
if len(part) == 2:
first = part[0]
middle = None
last = part[1]
db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?, ?, ?, ?, ?)",first, middle, last, house, birth)
elif len(part) == 3:
first = part[0]
middle = part[1]
last = part[2]
db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES (?, ?, ?, ?, ?)",first, middle, last, house, birth)
And rooster:
from sys import exit
from sys import argv
from cs50 import SQL
import cs50
import sys
import sqlite3
if len(argv) != 2:
print("missing command-line argument")
exit(1)
db = SQL("sqlite:///students.db")
rows = db.execute("SELECT * from students WHERE house = :house ORDER BY last,first", house = sys.argv[1])
for row in rows:
if row["middle"] is None:
print("{} {}, born {}".format(row["first"], row["last"], row["birth"]))
else:
print("{} {} {}, born {}".format(row["first"], row["middle"], row["last"], row["birth"]))
Thank you so much for your help!