Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

use python Implement a program to import student data into a database and produce class rosters. $ python3 import.py characters.csv $ python3 roster.py Gryffindor Lavender

use python

Implement a program to import student data into a database and produce class rosters.

$ python3 import.py characters.csv $ python3 roster.py Gryffindor Lavender Brown, born 1979 Colin Creevey, born 1981 Seamus Finnigan, born 1979 Hermione Jean Granger, born 1979 Neville Longbottom, born 1980 Parvati Patil, born 1979 Harry James Potter, born 1980 Dean Thomas, born 1980 Romilda Vane, born 1981 Ginevra Molly Weasley, born 1981 Ronald Bilius Weasley, born 1980

Download this file which you are going to use for this problem. After extracting this file, you should see a characters.csv file and a students.db database. There are also two Python files, import.py and roster.py, which contain nothing and these are where you're going to type your work.

Background

Hogwarts is in need of a student database. For years, professors have been maintaining a CSV file containing all of the students' names and houses and years. But that file didn't make it easy to get access to certain data, such as a roster for all the Ravenclaw students, or an alphabetical listing of the students enrolled at the school.

Hence, you need to write a Python program to import all of the school's data into a SQLite database, and another Python program to query that database to get house rosters for each of the houses of Hogwarts.

Specification

In import.py, write a program that imports data from a CSV file.

  • Your program should accept the name of CSV file via command-line argument.
    • If an incorrect number of command-line arguments are provided, your program should print an error and exit.
    • You may assume that the CSV file will exist, and will have columns name, house, and birth.
  • For each student in the CSV file, insert the student into the students table in the students.db database.
    • While the provided CSV file has just a name column, the database has separate columns for first, middle, and last names.
    • You need to parse each name and separate in into first, middle, and last names.
    • You may assume that each person's name field will contain either two space-separated names (a first and last name) or three space-separated names (a first, middle, and last name).
    • For students without a middle name, you should leave their middle name field as NULL in the table.
    • The table already exists in the database with the appropriate columns, so no need to create a new table.

In roster.py, write a program that prints a list of students for a given house in alphabetical order.

  • Your program should accept the name of a house as a command-line argument. If an incorrect number of command-line arguments are provided, your program should print an error and exit.
  • Your program should query the students table in the students.db database for all of the students in the specified house.
  • Your program should print each of the student's full name and birth year (formatted as Harry James Potter, born 1980 or Luna Lovegood, born 1981).
    • Each student should be printed on their own line.
    • Students should be ordered by last name. For students with the same last name, they should be ordered by first name.

Testing

$ python3 import.py characters.csv $ python3 roster.py Gryffindor Lavender Brown, born 1979 Colin Creevey, born 1981 Seamus Finnigan, born 1979 Hermione Jean Granger, born 1979 Neville Longbottom, born 1980 Parvati Patil, born 1979 Harry James Potter, born 1980 Dean Thomas, born 1980 Romilda Vane, born 1981 Ginevra Molly Weasley, born 1981 Ronald Bilius Weasley, born 1980 $ python3 roster.py Hufflepuff Hannah Abbott, born 1980 Susan Bones, born 1979 Cedric Diggory, born 1977 Justin Finch-Fletchley, born 1979 Ernest Macmillan, born 1980 $ python3 roster.py Ravenclaw Terry Boot, born 1980 Mandy Brocklehurst, born 1979 Cho Chang, born 1979 Penelope Clearwater, born 1976 Michael Corner, born 1979 Roger Davies, born 1978 Marietta Edgecombe, born 1978 Anthony Goldstein, born 1980 Robert Hilliard, born 1974 Luna Lovegood, born 1981 Isobel MacDougal, born 1980 Padma Patil, born 1979 Lisa Turpin, born 1979 $ python3 roster.py Slytherin Millicent Bulstrode, born 1979 Vincent Crabbe, born 1979 Tracey Davis, born 1980 Marcus Flint, born 1975 Gregory Goyle, born 1980 Terence Higgs, born 1979 Draco Lucius Malfoy, born 1980 Adelaide Murton, born 1982 Pansy Parkinson, born 1979 Adrian Pucey, born 1977 Blaise Zabini, born 1979

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals Design And Implementation

Authors: David M. Kroenke

5th Edition

B000CSIH5A, 978-0023668814

More Books

Students also viewed these Databases questions