2

[33mTraceback (most recent call last):[0m

[33mFile "roster.py", line 34, in main()[0m

[33mFile "roster.py", line 27, in main

print(row[0] + " " + row[1]+" "+ row[2] + ", born "+ str(row[3]))[0m

[33mTypeError: can only concate...


import cs50
from sys import argv, exit
import csv
import sqlite3


def main():
    # db = cs50.SQL("sqlite:///students.db")
    db = sqlite3.connect("students.db")
    
    if len(argv) != 2:
        print("USAGE: python [file name] [house]")
        exit(1)
    
    cursor = db.cursor()   
        
    cursor.execute("SELECT first, middle, last, birth FROM students WHERE house=? ORDER BY last", (argv[1],))
    data = cursor.fetchall()
    
    # loop through all the data received
    for row in data:
        if (row[1] == "NULL"):
            print(row[0] + " " + row[2] + ", born "+ str(row[3]))
        else:
            print(row[0] + " " + row[1]+" "+ row[2] + ", born "+ str(row[3]))
    # Create a commit
    db.commit()

    # Close your database connection
    db.close()
    
main()
1

You must log in to answer this question.

Browse other questions tagged .