Write a function that will take two arguments

Assignment Help Python Programming
Reference no:

Exercise 1

The attributes of alecturer are name, payroll number, department and salary.

Write a function which takes a string argument, and creates and returns a tuple containing details of the lecturer specified by the string. The string should be assumed to have the format

12345 CSEE25000 Bartholomew Homer Simpson

The first three items in the line will be the payroll number, department and salary; the rest of the line will be the name, the last word of which is the surname. There will be no spaces in the department 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 areBartholomew Homer.)

Next, write a function that will print the details of a lecturer 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 CSEE  £25000

The name should be displayed using 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 department will contain more than 15 characters, payroll numbers will contain at most 5 digits and all salaries will be integers less than 100,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 lecturer-creation function, storing the tuples returned by this function in a list.

After the data has been input the program shoulddisplay details of all 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 full details of all of the employees from a particular department or the names (with no other details) of all lecturers with a salary in a particular range (e.g. 20000 to 30000), or quitting the program. The user should then be asked to supply the department or upper and lower 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 list of names for the salary-range output should be sorted alphabetically by last name (also using the first name if the last names of two employees are the same), but displayed using the format Bartholomew Homer Simpson.

Appropriate messages should be displayed if a search produces no results.

Exercise 2

This assignment 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. the following word grid it is possible to find the words active, stock, ethernet and java. Note that this exercise involves only horizontal and vertical words; words that occur diagonally (such as python) are not considered as being present in the grid.

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

 2.1 Inputting the Grid from a File

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 strigs.

After the input is complete the grid should be displayed on the screen.

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.

2.2 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 searchfor a horizontal (left-to-right or right-to-left) or vertical (downwards or upwards) occurrence of the word (e.g. activex and ethernet in the sample grid). 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 and last letters of the word (i.e. four integers). The top row should be regarded as row 1 and the leftmost column as column 0

2.3 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 dictionary using the word as a key.

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

active found: row 3 col 3 to row 3 col 8

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

Reference no:

Questions Cloud

How does downsizing affect employee morale : How does downsizing affect employee morale?
What are some of the contract negotiations : What are some of the contract negotiations that can be done and how can we successfully accomplish impasse resolution?
State the highest possible oxidation state for the halogens : If the highest possible oxidation state for the halogens is +7, and the lowest possible is -1 which of the following could not disproportionate?
Discuss the importance of communication and information : Discuss the importance of communication and information exchange to project success. What are the crucial features and elements of effective communication and information exchange in successful projects?
Write a function that will take two arguments : Write a function that will take two arguments: a word to be searched for and a list of strings containing the grid and write code to read, in turn, each line of the file, remove the newline character and append the resulting string to a list of stri..
Non-security personnel in emergency plan-disaster response : What role should non-security personnel play in an emergency plan and disaster response? Should these roles be included in a procedures manual? Why or why not? How can a company or organization balance safety and liability issues with the use of non-..
Calculate motor speed in revolutions per minute : 4.What is the fundamental benefit of PLC controls over manual controls 5.Describe the differences between the two methods of scanning during PLC logic solving. Which method holds the advantage over the other
What are examples of virtues, values, and moral concepts : What are examples of virtues, values, and moral concepts? How do each of these relate to one another? In what ways are they separate and in what ways are they connected?
Find the imaginary part and real part of function : Find the imaginary part of e^ - (j pi)/2 Find the magnitude of e^ jtheta (for any real value of theta) Find the magnitude of Ae^( j theta) (for any real values of A and theta) Find the phase of -5j in radians

Reviews

Write a Review

Python Programming Questions & Answers

  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.

  Function should return a dictionary

Write a function numOccur(s), where s is a string; the function should return a dictionary whose keys are the 26 ascii letters abcdefghijklmnopqrstuvwxyz

  Program to do the enciphering

Write a program to do the enciphering. It should prompt the user for a message, and print out both the entered message and its corresponding ciphertext.

  Define three types of programming errors

Define three types of programming errors and explain with examples

  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.

  Permutation ciphers

Permutation Ciphers (a.k.a. Transposition Ciphers) are another class of simple cryptosystems. For this we use the functions apply(.,.) and inv(.) from Homework 4; copy these two functions into your le as auxiliary functions.

  Write a python program that computes the mean, median, mode

How to write a python program that computes the mean, median, and mode?

  The function should return the day name (''su'',''mo''..etc)

Write the function day(d,m) where m is an integer from 1 through 12 expressing a month, and d is an integer from 1 through 31 expressing the day part of a date in 2014.

  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.

  Write a program using the ''requetinteger''

using python/jython programming write a program using the 'requetInteger' function that will ask the user to type a value that will draw a line from one point on a picture to another. I don't need specific help just a gerneral idea.

  The block of statements below the line of stars

The block of statements below the line of stars is where I need help correcting. The true line that needs to be corrected is p = add((getX(k),getY(r))), it needs to give points of the path using the block of information. I have somthing which I kn..

  Write a program that does simple packet routing

Write a program that does simple packet routing and your program will take three command-line arguments:

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