-
Notifications
You must be signed in to change notification settings - Fork 0
/
roster.py
32 lines (20 loc) · 897 Bytes
/
roster.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# TO DO: program that prints a list of students for a given house in alphabetical order.
import sys
import csv
import cs50
# Command line arguments check. exit as 1 if not correct.
if len(sys.argv) != 2:
print("Usage: python roster.py Slytherin")
sys.exit(1)
# loading the students db to sqlite3 and sqlite3 to python.
db = cs50.SQL("sqlite:///students.db")
# execute SQL query to SELECT roster from house list.
houses = db.execute("SELECT first, middle, last, birth FROM students WHERE house = (?) ORDER BY last, first", sys.argv[1])
for row in houses:
# Take account lack of middle name for some students.
if row["middle"] == None:
print(row["first"] + " " + row["last"] + ", born " + str(row["birth"]))
# If Data is complete.
else:
print(row["first"] + " " + row["middle"] + " " + row["last"] + ", born " + str(row["birth"]))
sys.exit(0)