Lab Assignment #11b Based upon Dr. Keyser’s Original 1 Revised Spring 2020 TLF ENGR 102 – Spring 2021 Sections 501 and 502 Dr. Fullerton Lab Assignment #11b Deliverables: There are several...

Prompt attached. All information required is attached


Lab Assignment #11b Based upon Dr. Keyser’s Original 1 Revised Spring 2020 TLF ENGR 102 – Spring 2021 Sections 501 and 502 Dr. Fullerton Lab Assignment #11b Deliverables: There are several deliverables for this individual assignment, however they can all be organized into one file. Organize your file such that all function definitions are near the top following any import statements. Then write main code underneath to test each of the functions. Please comment your code so that we can follow what you are doing. Please submit the file to the Submission Box labeled “Lab Assignment 11b Individual Activities”. The file should be named as listed below: • Lab11b_Act1.py program file with all function definitions and main code for testing Your file should be structured as follows: • Header information at the top. • import statements under the header. • Function definitions under the import statements. • Main code which tests each function below the function definitions o Please include comments so that we may easily find the various parts of your code. Please refer to the posted document “Commentary on Lab 11b.pdf” for additional information. Activity #1: Programs to test writing functions – to be done individually. This activity is meant to give you more experience writing functions. a) Imagine that you have a block of material in which a hole has been drilled: Write a function that will take as parameters the following four dimensions of the box: 1) length, 2) width, and 3) height, and 4) the radius of the hole. Your function should calculate and return the volume of material remaining. Assume the hole has been drilled along the height direction. Also assume that the hole is drilled in the center of the face. Note: Check that the specified radius is less than min(length/2, width/2). If it is not, your function should return an error message of some sort. You may assume that the units among the input parameters are consistent. b) Imagine that you have three parallel lists of the same length, one with the names of several production facilities, another with the annual cost to operate each of those facilities, and a third with the value of the products produced at each facility. Write a function that takes as parameters the three lists described above and returns both the name and net profitability Lab Assignment #11b Based upon Dr. Keyser’s Original 2 Revised Spring 2020 TLF (profitability is the value of what is produced minus the cost to operate) of the least profitable facility. c) Write a function that takes as parameters a person’s name, city, state, zip code, and address, where the address is either one string (one line) or two strings (two lines) and prints the person’s information like a mailing label. Show that the routine works regardless of whether it is called with one address line or two address lines. d) Write a single function that takes a Python list of floating-point numbers as an input parameter and returns the minimum and maximum values from the list along with the mean value of the list elements. (Note: We have written this code before, just not as a function. It’s okay to reuse the existing code. Simply create a function definition around the existing code.) e) Write a function that takes as parameters two parallel lists: a list of times (in increasing order), and a list of positions of a particle that correspond with the time values. The function should return a new list giving the average velocity between consecutive time measurements. The new list should have length one less than the original lists. ENGR 102 – Spring 2021 Sections 501 and 502 Dr. Fullerton Commentary on Lab Assignment #11b Here are a few comments on the Lab Assignment 11b activities. Part (a) • Keep it simple o Send the four parameter values to the function ▪ Don’t worry about units – assume they are all the same o Check that radius is small enough to fit on the face length X width ▪ If not, return an error • Could be something like the integer -999 so that the calling code will recognize that this is not a valid volume o If the radius is small enough, calculate the volume remaining and return it • In the file that you submit, demonstrate the function o Create variables for the four values o Call the function o Catch the return value in a variable o Print the result Part (b) “Three parallel lists” means that there are three Python lists, each with a different name, such that elements in the same position correspond with each other. For example, for the following data, Facility Name Annual Operating Cost (millions) Annual Value of Products (millions) ABC Corporation 75.1 135.7 General Manufacturing 103.8 200.1 Specialty Products 99.2 188.3 define three Python lists as follows: facilityName = [ ‘ABC Corporation’, ‘General Manufacturing’, ‘Specialty Products’] annualCost = [75.1, 103.8, 99.2] annualValue = [135.7, 200.1, 188.3] Now, if you create a loop for the list index, element[0] in each list corresponds to ABC Corporation, and element[1] in each list corresponds to General Manufacturing. “Profitability” is the difference between “value” and “cost”. Part (c) This is pretty straightforward. You are writing a function to print mailing labels. The only trick is that sometimes the address needs just one line and sometimes it needs two. Your function should recognize how many lines are required and print accordingly. There are lots of clever ways to accomplish this, so I’ll let you try to figure this out before giving too much away. Note: As a general rule, I do not recommend getting input from the keyboard inside a function nor do I recommend printing from within a function. It is usually better to put all the input in the same place and all the output in the same place for debugging purposes. Having said that, this function only exists to print something in a specified format, so it is reasonable to print from the function. However, you should pass the required info to the function as parameters – don’t get keyboard input from within the function. Part (d) Not much to say here. In your file, hard code a Python list with several float values. Then call your function by passing that list as a parameter. The function returns three values, so you will need to use a tuple in the function and in the main code. (See example posted with Class Slides.) Part (e) Here we have two parallel lists: one has time values and the other position values. This may be data from a physics lab in which distance is measured at discrete time increments. We would like to use this data to estimate the average velocity versus time. There are a couple of ways to do this, but all the ways involve estimating velocity as Δ????????/Δ????. So, loop through the two lists, calculate a velocity value, and store in a new list. The new list will have one fewer element than the original two lists.
Apr 12, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here