Assume a database of records named \'Students\' exists in memory where each reco
ID: 3773574 • Letter: A
Question
Assume a database of records named 'Students' exists in memory
where each record is represented as a list. A record contains
a student's last name, first name, student ID number, age, amount
of money owed to the university, father's first name,
mother's first name, and class year. Assume the database is sorted
according to last name (primary key). If multiple students
have the same last name, assume their records are sorted by student's
first name (secondary key).
Some example records would be:
['Brooks', 'Kim', 718337185, 18, 0.0, 'Christopher', 'Christine', 'freshman']
['Daniels', 'Chester', 797701002, 18, 8220.01, 'Charlie', 'Beverly', 'freshman']
['Daniels', 'Chris', 810199144, 20, 0.0, 'Jack', 'Clair', 'senior']
['Jones', 'Joe', 700157834, 19, 17395.57, 'Daniel', 'Susan', 'junior']
['Lowenstern', 'Ike', 877377100, 21, 813.3, 'Jacob', 'Laura', 'senior']
['Updegrave', 'Douglas', 711922910, 19, 0.0, 'Philip', 'Leticia', 'sophomore']
"""
Write Python code that will print the full records of students that are seniors
Explanation / Answer
As you are assuming the student details exist in memory as a list, the following code will work
students = [
['Brooks', 'Kim', 718337185, 18, 0.0, 'Christopher', 'Christine', 'freshman'],
['Daniels', 'Chester', 797701002, 18, 8220.01, 'Charlie', 'Beverly', 'freshman'],
['Daniels', 'Chris', 810199144, 20, 0.0, 'Jack', 'Clair', 'senior'],
['Jones', 'Joe', 700157834, 19, 17395.57, 'Daniel', 'Susan', 'junior'],
['Lowenstern', 'Ike', 877377100, 21, 813.3, 'Jacob', 'Laura', 'senior'],
['Updegrave', 'Douglas', 711922910, 19, 0.0, 'Philip', 'Leticia', 'sophomore'],
]
for std in students:
if(std[len(std)-1] == "senior"):
print(std)
--output--
sh-4.3$ python main.py
['Lowenstern', 'Ike', 877377100, 21, 813.3, 'Jacob', 'Laura', 'senior']
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.