meematz
meematz

Reputation: 127

cs50 pset7 houses roster

My roster.py function in pset7 works as it should except for the fact that it returns 4 or 5 copies of the name and birthyear instead of just one. Through debugging you can see that the problem is with the results variable. It stores all of the copy pasted names instead of one name.

Heres my code:

import sys
from cs50 import SQL

if len(sys.argv) != 2:
    print("Needs two command-line argument")
    exit(1)

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

house = sys.argv[1]

results = db.execute("SELECT * FROM students WHERE house = ? ORDER BY last ASC, first ASC", house)


for row in results:
    if row["middle"] != None:
        print(f'{row["first"]} {row["middle"]} {row["last"]}, born {row["birth"]}')
    else:
        print(f'{row["first"]} {row["last"]}, born {row["birth"]}')

Upvotes: 0

Views: 439

Answers (1)

Haseeb Ahmed
Haseeb Ahmed

Reputation: 265

Go into your students.db, go in students table, empty your table, Then Run Following Command and make sure to run import.py once

$ python import.py characters.csv
$ python roster.py Gryffindor

if you run more than once import.py then there will be more copies and you will need to empty the table

Upvotes: 1

Related Questions