I’ve got this as a homework question and dont know how I should go about it.
Firstly, I’ve been given a dataset with a list of employees’ names, addresses, emails etc. with about 50 employees in total.
You are asked to write an application to provide information about the members of staff. Your program should prompt the user to enter search criteria. Any members of staff who match the search criteria should be printed to the screen in the following format:
Position Designation Room and Extension Name and Email Address
(columns are tab-separated)Matching information…………
You will have to amend the dataset for processing, and you may choose to hold this in a separate file, although this is not necessary. Your program should satisfy certain constraints:
- You should compare each column in the dataset against the search criteria.
- The comparisons should not be case-sensitive.
- All output should be in initial capitals, apart from the email address.
- If a match is found, the results line should be printed and the columns should all line up.
- Where there is no match, a message should be printed, without a title line.
You should save (1) your program, and (2) a paragraph to explain HOW you accomplished the processing of the dataset.
You should also run these test cases on your application:
- Search for ‘brenda’
- Search for all clerical staff.
- Search for ‘BredNa’
- Find Dr Carr’s position
- Which office is Neil located in?
So, firstly, how should I read this dataset? Should I read it in as a text file or create a tuple, dictionary? etc.
staff = [['prof.liam maguire','head of school','academic','MS127','75605','lguire@ulster.ac.uk'],
['prof. martin McGinnity','director of intelligent systems research centre','academic','MS112','75616','tinnity@ulster.ac.uk'],
['dr laxmidhar Behera','reader','academic','MS107','75276','lra@ulster.ac.uk'],
['dr girijesh Prasad','professor','academic','MS137','75645','gad@ulster.ac.uk'],
['dr kevin Curran','senior lecturer','academic','MS130','75565','krran@ulster.ac.uk'],
['mr aiden McCaughey','Senior Lecturer','academic','MG126','75131','aughey@ulster.ac.uk'],
['dr tom Lunney','postgraduate courses co-ordinator (Senior Lecturer)','academic','MG121D','75388','tfney@ulster.ac.uk'],
['dr heather Sayers','undergraduate courses','co-ordinator (Senior Lecturer)','academic','MG121C','75148','hmyers@ulster.ac.uk'],
['dr liam Mc Daid','senior lecturer','academic','MS016','75452','ljid@ulster.ac.uk'],
['mr derek Woods','senior lecturer','academic','MS134','75380','dnoods@ulster.ac.uk'],
['dr ammar Belatreche','lecturer','academic','MS104','75185','aatreche@ulster.ac.uk'],
['mr michael Callaghan','lecturer','academic','MS132','75771','mjllaghan@ulster.ac.uk'],
['dr sonya Coleman','lecturer','academic','MS133','75030','saeman@ulster.ac.uk'],
['dr joan Condell','lecturer','academic','MS131','75024','jdell@ulster.ac.uk'],
['dr damien Coyle','lecturer','academic','MS103','75170','dhle@ulster.ac.uk'],
['mr martin Doherty','lecturer','academic','MG121A','75552','merty@ulster.ac.uk'],
['dr jim Harkin','lecturer','academic','MS108','75128','jgrkin@ulster.ac.uk'],
['dr yuhua Li','lecturer','academic','MS106','75528','yi@ulster.ac.uk'],
['dr sandra Moffett','lecturer','academic','MS015','75381','soffett@ulster.ac.uk'],
['mrs mairin Nicell','lecturer','academic','MG127','75007','micell@ulster.ac.uk'],
['mrs maeve Paris','lecturer','academic','MG040','75212','m@ulster.ac.uk'],
['dr jose Santos','lecturer','academic','MG035','75034','jantos@ulster.ac.uk'],
['dr nH. Siddique','lecturer','academic','MG037','75340','nhique@ulster.ac.uk'],
['dr zumao Weng','lecturer','academic','MG050','75358','zmng@ulster.ac.uk'],
['dr shane Wilson','lecturer','academic','MG038','75527','s.on@ulster.ac.uk'],
['dr caitriona carr','computing and Technical Support','MG121B','75003','crr@ulster.ac.uk'],
['mr neil McDonnell','technical Services Supervisor','computing and Technical Support','MS030 / MF143','75360','ndonnell@ulster.ac.uk'],
['mr paddy McDonough','technical Services Engineer','computing and Technical Support','MS034','75322','p.ugh@ulster.ac.uk'],
['mr bernard McGarry','network Assistant','computing and Technical Support','MG132','75644','bgrry@ulster.ac.uk'],
['mr stephen Friel','secretary','clerical staff','MG048','75148','siel@ulster.ac.uk'],
['ms emma McLaughlin','secretary','clerical staff','MG048','75153','eughlin1@ulster.ac.uk'],
['mrs. brenda Plummer','secretary','clerical staff','MS126','75605','blmmer@ulster.ac.uk'],
['miss paula Sheerin','secretary','clerical staff','MS111','75616','perin@ulster.ac.uk'],
['mrs michelle Stewart','secretary','clerical staff','MG048','75382','mwart@ulster.ac.uk']]
matches = []
criterion = input ("please enter search criterion: ")
criterion = criterion.lower()
for person in staff:
for characteristic in person:
if characteristic in person:
if criterion in characteristic:
matches.append(person)
break
if len(matches) == 0:
print("No Match")
else:
print("POSITION |||DESIGNATION ||| EXT & ROOM NO||| NAME & EMAIL")
for i in matches:
print (i[1].title(),': ',i[2].title(),':',i[3].upper()+ i[4],':',i[0].title(), i[5].title())`
This is what ive came up with so far and it seems to work, is there any improvements you would make?
Thank you for being honest and telling us that this is a homework question. StackOverflow discourages straight-up giving out answers to homework questions, but we can guide you towards the correct answer.
With regards to “amend the dataset for processing”: This implies that the data is not currently in a consistent format. The first thing you need to do is look at the data you’ve been given, and decide the best representation for the data.
I’d recommend a columnar tab-delimited data file- this is easily created in Microsoft Excel by placing the data in a spreadsheet, and saving it as text. (Excel will complain that it will lose all the various things that make it a spreadsheet instead of a text file, but that’s okay- you want a text file.) Save the updated file.
Excel produced what’s called a tab-delimited text file: a 2-dimensional grid of data (like the shape of a spreadsheet), represented with one row of data per line (rephrased, the linebreak symbol is used to separate rows of data, which text editors interpret as a command to start writing on a new line), and the tab character (written in Python within an escaped string as
\t, but really a single character of its own) separating cells within each row. This is also known as tab-separated values, or TSV. Closely related is comma-separated values, or CSV, which is another option in Excel. CSV can also stand for character-separated values, which is the general term for any text file representing a grid of data by using some character (‘,’ for comma-separated, ‘\t’ for tab-separated) to separate records.CSVs are a very common file format, so Python is ready to help you out here. Python has a library, csv, designed to read these files for you. If you used Excel text format, you’ll need to tell it your
dialectisexcel-tab, since that symbolizes tab-delimited files as Excel outputs them.You’ll need to construct a
csv.readerto read your formatted data file. Use the order you put the columns in to understand the lists that you get when you read the CSV one line at a time- the order of the columns and the order of the items in each row is the same, so use that information to index correctly into the list to find each field.Once you’ve read a row, what do you want to do with it?
You have a choice of storage formats in your program:
The second approach is much faster for repeated queries, since you’re organizing all the records at the start for fast lookup. The first is much easier to implement, however, and is more likely to be what your teacher expects. I’d recommend implementing the first, understanding it, and then if you have time, implement the second.
The user interface for all this is up to you, of course, but this should put you well on your way to implementing the core of the program. Good luck.