In this Mini-Lab, you will need to complete the two following activities: (see attached file)
In this Mini-Lab, you will need to complete the two following activities: (see attached file)
Lab: Modules Overview This lab introduces modules , which allow the usage of functions from different files. You’ve already seen the use of module import, as random, math , and scipy . Imagine a large program that calls several different functions you’ve defined within it. Now, you’d like to make a second program – and many of the functions in the first are very helpful in the second. You could rewrite them again in the second program, or simply import them, which allows access to them without having to rewrite anything. Here we will import functions you’ve w ritten to illustrate how importing works . As long as both files are in the same directory, it can be import ed. Python also has a special directory within its installation folder that stores packages that are installed from the web or elsewhere (like SciPy) . When using the import keyword, this directory as well as the directory you’re working in are searched for the module. Lab Activities • Exercise 1: Creating a Function • Exercise 2: Im porting a Function Page 2 Exercise 1: Create a Function to Calculate the Cost of Gas Overview: In the drive to work program, we have been asking the user for the cost of gasoline, but h aven’t put that variable to use. We will make a function now that takes in cost, distance, the usage rate, and returns a total. 1. Open from last lab. • Reopen the program. If you haven’t closed it, it should exist as a tab in Spyder. • If you have lost this file, just create a new blank file. • Clear out the main portion of this file, leaving only the function def initions. 2. Define a function calc_price(cost, distance,rate): • Recall, rate is in distance per unit of fuel. • You will need to calculate the units of fuel for a given distance, multiply that by cost , and return the value. • Create a DocString for this function (“””underneath the def line, with triple quotes”””) that describes what it does. • Test your function within this program t o verify it calculates properly, e.g.: • calc_price(3,100,200) should return 6.0 3. Import your new function to another program. • Open any of the programs we’ve created before, or open a new file. • Because Spyder saves all of these files in the sam e directory, they all have access to each other using import. • Type import function_test near the top of this file. You now have access to those functions! Page 3 • Now, anywhere within the main portion of this program, type: • function_test. • Anaconda will list the av ailable functions. You should have do_exp (if you used your last ) and calc_price. Also you have access to random , since it was imported for • Choosing calc_price, clicking the word so the cursor is within it, and hitting Ctrl+I shows the DocString you wrote earlier. • Try calling one of those functions and running the program. Remember to use print lines where necessary to verify results. Page 4 Exercise 2: Import the Function into Overview: We will now implement our function into the Drive to Work program stored in 1. Import your function into • Open branc and import function_test . Remember imports should happen at the top of the program underneath. • Verify it is usab le by typing: function_test. Spyder should show you the available functions. • Call your calc_price function above the while loop for review , using the appropriate values taken from the user. • Add a print line within the review section that reports the t otal cost of the trip, based on the value returned by function_test.calc_price(). • Remember to use the appropriate format specifiers for currency! • You can also add to the #reporting strings section in case the user doesn’t want to review the values, but wou ld still like to know how much they expect to spend on this trip. 2. Test your program • Run the program and verify it works as intended. • If you have issues, make sure indentation is correct (Remember, we have multiple loops!)

Why Choose Us

  • 100% non-plagiarized Papers
  • 24/7 /365 Service Available
  • Affordable Prices
  • Any Paper, Urgency, and Subject
  • Will complete your papers in 6 hours
  • On-time Delivery
  • Money-back and Privacy guarantees
  • Unlimited Amendments upon request
  • Satisfaction guarantee

How it Works

  • Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
  • Fill in your paper’s requirements in the "PAPER DETAILS" section.
  • Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
  • Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
  • From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.