gpt4 book ai didi

python - cs50 pset7包含语法

转载 作者:行者123 更新时间:2023-12-03 08:19:32 26 4
gpt4 key购买 nike

我正在解决问题的roster.py部分,但出现错误:

   File "roster.py", line 17
print(f"{row["first"]} {row["middle"]} {row["last"]}, born {row["birth"]}")
^
SyntaxError: invalid syntax
我的代码:
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 = ?", 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"]}")

最佳答案

您的报价有误。尝试这个:

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"]}')

关于python - cs50 pset7包含语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63497295/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com