Creates and returns a tuple containing details of employee

Assignment Help Python Programming
Reference no: EM131775922 , Length: 5

Exercise 1

The attributes of an employee are name, payroll number, job title and salary.

In the file ex1.py write a function which takes a string argument, and creates and returns a tuple containing details of the employee specified by the string. The string should be assumed to have the format

12345 25000 Consultant Bartholomew Homer Simpson

The first three items in the line will be the payroll number, salary and job title and the rest of the line will be the name. There will be no spaces in the job title but there will be spaces in the name. The tuple should contain exactly 5 items: the payroll number, salary, job title, surname and other names. (The other names should be stored as a single string; the surname will be the last name in the input line so in the example above the surname is Simpson and the other names are Bartholomew Homer. You should not assume that all employees will have exactly two other names; some may have just one and others may have more than two.)

Next, write a function that will print the details of an employee on a single output line. It should take a tuple as its argument and print the details in fixed-width fields using a layout such as
Simpson, Bartholomew Homer 12345 Consultant £25000

The name must be displayed in a single fixed-width fieldusing the format shown above so you will need to create a string containing the name in this format and print it in a fixed- width field. You may assume that no name will contain more than 30 characters when displayed in this format, no job title will contain more than 15 characters, payroll numbers will contain at most 5 digits and all salaries will be integers less than 1,000,000.

In the main body of the program, write code which prompts the user for a filename and attempts to open the file whose name is supplied. If the file cannot be opened an error message should be output and the program should terminate; otherwise the program should read each line from the file and supply it to the employee tuple-creation function, storing the tuples returned by this function in a list. You may assume that the file contains lines that conform to the format described for the argument to the function.

After the data has been input the program should display details of all the employees in the list in a neat table (using the function already written) then enter a loop in which the user should be given the option of requesting the display of (a) full details of (i) the employee with a given payroll number or (ii) all employees with a salary in a particular range (e.g. 20000 to 30000) or (b) the first and last names of all employees with a specified job title using the format Bartholomew Simpson (other names, when they exist, must not be output) or quitting the program. The user should then be asked to supply the job title, payroll number or lower and upper bounds of the salary range (as appropriate), the list should then be searched and the appropriate output displayed (using the function written earlier when full details are required). The salary output should be sorted numerically in ascending order of salary.. Appropriate messages should be displayed if a search produces no results. The user should be told what has to be typed in order to select each option; the input options should be concise (e.g. ‘1', ‘2' etc. or ‘j', ‘s' etc.) in order to allow quick testing of the program.

Exercise 2

This exercise involves writing a program to solve word search puzzles. For example in the following word grid it is possible to find the words active, stock, ethernet and java.

xmmycxvtljlqbbybkoumjqwbtbufve
buubmekxbeydqmcnzyjpvdankomdmi
lqactivexnyvwdvcoshoyrohgvfvqj
vsewohvnbxsduqjiffkoyhpdwbrngc
dvqwwwfkoyamapmlrrjvtkljpcvkua
iqqfxtumsjvfmtrsbycyqiarixqikp
afgrvlqzdqaxaoanfqplmjpjhnzams
yofywrbpfcjiflcbbcoecxpwljyuyt
twyxetyuyufvvmcuawjmbwlqhxjgqo
txekdexmdbtgvhpyvsqtmljdxeqltc
dcctenrehteoxqdgnueljtrrnesgok
oqsnakqwerouftmgnjqbytjzhmwncc

Inputting the Grid from a File

In the file ex2.py write code to prompt the user for a filename, and attempt to open the file whose name is supplied. If the file cannot be opened the user should be asked to supply another filename; this should continue until a file has been successfully opened.

The file will contain on each line a row from the grid. For example the first two lines of a file that contains the grid shown on the previous page would be

xmmycxvtljlqbbybkoumjqwbtbufve
buubmekxbeydqmcnzyjpvdackomdmi

Write code to read, in turn, each line of the file, remove the newline character and append the resulting string to a list of strings.

After the input is complete the strings in the list should be displayed on the screen, one per line.

Note that grids used for testing the submitted programs may have different widths and heights from the sample one that will be provided. Grids will contain only lower-case letters.

The Word-Search Function

Write a function that will take two arguments: a word to be searched for and a list of strings containing the grid.

The function should search for a horizontal (left-to-right or right-to-left) or vertical (downwards or upwards) occurrence of the. If a word occurs more than once the function is required to find only one occurrence so you should stop searching once the word has been found.

[ It is recommended that you first write a function that just searches for horizontal occurrences and then write the code for section 2.3 to allow the function to be tested before adding code to the function to search for vertical occurrences. ]

If the word has not been found None should be returned; if the word has been found the function should return a tuple, containing the row and column numbers of the first letter of the word and a string indicating the direction (i.e. four integers). The top row should be regarded as row 1 and the leftmost column as column 1.

The Word-Search

After displaying the grid, the program should ask the user to supply a name of a file containing words to be searched for, one word per line. This file should be opened, once again asking the user to supply another name if necessary. You should supply each word in this file in turn to the word-search function. If the function returns None the word should be added to a list of words that have not been found; otherwise the tuple returned should be added to a dict object using the word as a key.

After searching for all of the words you should display details of all of the words in the dictionary (in alphabetical order) using a format such as

active found: left to right from row 3 col 3

Finally you should output a list of the words that were not found (also in alphabetical order).

Documentation and Commenting
All functions in each of the programs should have documentation strings stating precisely what they do (but not how they do it), what their arguments are and what they return.

Within function bodies occasional brief comments, such as "search upwards" or "sort by surname" should be used to indicate what is being done by blocks of code - comments stating what each individual line does should not be provided.

Reference no: EM131775922

Questions Cloud

Why a mission statement should not include monetary amounts : Explain why a mission statement should not include monetary amounts, numbers, percentages, ratios, goals, or objectives.
Prepare the journal entry to record this payment : Assume that Steffens Co. paid the balance due to Bryant Company on May 4 instead of April 15. Prepare the journal entry to record this payment
Compute the amount of accumulated depreciation : Compute the amount of accumulated depreciation on each machine at December
Why do economic costs include both explicit : 1.) Why do economic costs include both explicit (revealed and expressed) costs and implicit (present but not obvious) costs?
Creates and returns a tuple containing details of employee : CE151 - creates and returns a tuple containing details of the employee specified by the string. The string should be assumed to have the format
Cfo is gathering information to forecast the investment need : If the CFO estimates that he can receive an annual yield of 9% on his portfolio, what lump sum amount must he invest today to create the six year payout
Discuss the assumptions implicit in the shortcut : Sometimes engineers use a shortcut method for determining the average process performance. In this shortcut, the average variable value is used.
Create a shortage of gasoline : A price ceiling would create a shortage of gasoline, as you correctly explained. If prices were free to adjust, they would increase, you are right.
Resources from an allocative perspective : How does the growth in the area of providing clean water reflect an effective use of resources from an allocative perspective?

Reviews

len1775922

12/21/2017 2:02:09 AM

Submission of this assignment will be via FASer; you will not be required to demonstrate your programs in the lab. It is expected that marks and feedback will be returned by the middle of week 17. You should refer to sections 5 and 7 of the Undergraduate Students’ Handbook for details of the departmental policy regarding late submission and plagiarism; the work handed in must be entirely your own. This assignment comprises two exercises, to be written as separate programs in files called ex1.py and ex2.py. Each will contribute 45% of the mark. The remaining 10% of the total mark for the assignment will be awarded for programming style and documentation. Sample data files to be used for testing the programs will be supplied.

len1775922

12/21/2017 2:01:56 AM

Marking Scheme Exercise 1: 15 marks will be awarded for the successful input of the data into tuples and the output of the list of employees; the remaining 30 marks will be available for successful searching. Exercise 2: 7 marks will be available for section 2.1, 25 marks for section 2.2 and 18 marks for section 2.3. The remaining 10 marks will be awarded for documentation and commenting; the maximum mark available will be proportional to the amount of the assignment attempted.

len1775922

12/21/2017 2:01:49 AM

If you have attempted both exercises place your two files ex1.py and ex2.py in a single .zip or .7z file and submit this to FASER. The file must be in one of these two formats; marks will be deducted for work submitted in any other format. If you have attempted just one of the two exercises it is acceptable to submit a single .py file.

Write a Review

Python Programming Questions & Answers

  Write a python program to implement the diff command

Without using the system() function to call any bash commands, write a python program that will implement a simple version of the diff command.

  Write a program for checking a circle

Write a program for checking a circle program must either print "is a circle: YES" or "is a circle: NO", appropriately.

  Prepare a python program

Prepare a Python program which evaluates how many stuck numbers there are in a range of integers. The range will be input as two command-line arguments.

  Python atm program to enter account number

Write a simple Python ATM program. Ask user to enter their account number, and print their initail balance. (Just make one up). Ask them if they wish to make deposit or withdrawal.

  Python function to calculate two roots

Write a Python function main() to calculate two roots. You must input a,b and c from keyboard, and then print two roots. Suppose the discriminant D= b2-4ac is positive.

  Design program that asks user to enter amount in python

IN Python Design a program that asks the user to enter the amount that he or she has budget in a month. A loop should then prompt the user to enter his or her expenses for the month.

  Write python program which imports three dictionaries

Write a Python program called hours.py which imports three dictionaries, and uses the data in them to calculate how many hours each person has spent in the lab.

  Write python program to create factors of numbers

Write down a python program which takes two numbers and creates the factors of both numbers and displays the greatest common factor.

  Email spam filter

Analyze the emails and predict whether the mail is a spam or not a spam - Create a training file and copy the text of several mails and spams in to it And create a test set identical to the training set but with different examples.

  Improve the readability and structural design of the code

Improve the readability and structural design of the code by improving the function names, variables, and loops, as well as whitespace. Move functions close to related functions or blocks of code related to your organised code.

  Create a simple and responsive gui

Please use primarily PHP or Python to solve the exercise and create a simple and responsive GUI, using HTML, CSS and JavaScript.Do not use a database.

  The program is to print the time

The program is to print the time in seconds that the iterative version takes, the time in seconds that the recursive version takes, and the difference between the times.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd