I’m working on the roster.py
part of the problem and I’m getting the error:
x
File "roster.py", line 17
print(f"{row["first"]} {row["middle"]} {row["last"]}, born {row["birth"]}")
^
SyntaxError: invalid syntax
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 = ?", 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"]}")
Advertisement
Answer
Your quotes are wrong. Try this:
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"]}')