EGR 103/Spring 2020/Lab 5

From PrattWiki
Jump to navigation Jump to search

Errors / Additions

None yet!

5.1 Introduction

The main purpose of this lab will be to look at debugging, dictionaries, loading data from files, and using Chapra Figure 4.2. There is also some string manipulation.

5.2 Resources

See main EGR 103 page for links to these

5.3 Getting Started

EGR 103/Getting Started

5.4 Ungraded

These problems are good ones to look at and to solve but are not a part of the graded work. Given that, you can absolutely consult with classmates about how to get the answers to these ungraded problems but you may not share those answers outside of the members of the class.

5.5 Useful Information

String and List Functions

This section discusses some of the most common functions applied to strings or to lists.

Debugging Introduction

See the videos at:

We will also go through debugging in lab using the Python:Debugging page.

5.6 Group-Based In-Lab Autograded Assignments

Pre-script: Remember that the autograder generally does not like raw code in scripts; if you have any tester code, be sure to put it all in a

if __name__ == "__main__":

structure.

Both of these require building dictionaries and using them. For they first problem, you could probably hard code the dictionary though that would take ten lines of code. For the second problem, you would not want to hard code 26 lines...

Instead, you could create a dictionary by first creating a list of keys and then a list of values. If you have those two lists, you can create the dictionary in two different ways:

Using a loop

If the lists are called KEYS and VALUES, respectively, you could create a dictionary with code like the following:

d = {}
for k in range(26):
    d[KEYS[k]] = VALUES[k]

Using zip

There is also a built-in function in Python called zip that will take the two lists and basically make a dictionary for you. If the lists are called KEYS and VALUES, respectively, you could create a dictionary with code like the following:

d = dict(zip(KEYS, VALUES)

See Section 9.7 of Punch & Enbody for examples of zip.


5.6.1 Based on P&E 9.26

For this problem it might be easy enough to simply hard-code the dictionary in the make_dict function. For example, one line in the function might look like:

    d[0] = "zero"

You will most likely want to figure out how to use zip, however, because you will definitely want to use zip in the next program.

5.6.2 Based on P&E 9.32

Because I am a nice person, I will mention that the following might be useful:

    points = [1, 3, 3,  2, 1, 4, 2, 4, 1, 8, 5, 1,  3,
              1, 1, 3, 10, 1, 1, 1, 1, 4, 4, 8, 4, 10]

5.7 Individual Lab Assignment

5.7.1

This problem takes you step by step through developing the code. Pay careful attention to the tests it recommends that you run. Put those tests in your script either in a main() function that gets called or in a selective executable based on whether __name__ is "__main__". Also look at the test code - make sure you understand what it is doing and how it works.

5.7.2

This is similar to 5.7.1. Including the part about looking at the test code and seeing how it works.

5.7.3

For this one, you will be making changes to an extended version of the Chapra 4.2 code in order to use accumulation to estimate values of cosine. It is very similar to using an accumulation to estimate values of the exponential.

5.7.4

For this one, you will be making changes to either the original or extended version of Chapra 4.2 in order to use a mapping to estimate roots of a function. It is very similar to using the Newton method mapping to estimate values of a square root. Note - though the mapping for the lab assignment comes from the Newton-Raphson, it origin is different from the Newton method discussed in class for finding a square root.

Class Document Protection