我roster.py在 pset7 中的函数正常工作,除了它返回 4 或 5 个姓名和出生年份的副本,而不是仅返回一个。通过调试可以看出问题出在结果变量上。它存储所有复制粘贴的名称而不是一个名称。这是我的代码:import sysfrom cs50 import SQLif 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"]}')
1 回答

Cats萌萌
TA贡献1805条经验 获得超9个赞
进入你的 students.db,进入 students 表,清空你的表,然后运行以下命令并确保运行 import.py 一次
$ python import.py characters.csv $ python roster.py Gryffindor
如果你多次运行 import.py 那么会有更多的副本,你将需要清空表
添加回答
举报
0/150
提交
取消