EGR 103/Spring 2023/Lab 6

From PrattWiki
Jump to navigation Jump to search

The following document is meant as an outline of what is covered in this assignment.

Typographical Errors

None yet!

APT

Acronym

  • Note that you need to name the file CreateAcronym.py while the function is named acronym
  • How can you split a string up based on a particular character? (perhaps I've said too much?)

BagFitter

  • Be sure to do this by hand yourself first and figure out what process you are using.
  • You may be asking yourself, "Wouldn't it be great if there were a way to get a collection of the unique items in a list?" And the answer is - it would be great! And so there is. A set is a collection of elements where each element is unique. If you cast some other collection (for example, a list or a string) as a set, the recast version will have as many elements as the number of unique entries in the original. If the original contains all the same type, the set will be ordered.
In [1]: set([1, 2, 3, 4, 5, 2, 4, 2])
Out[1]: {1, 2, 3, 4, 5}

In [2]: set("hello")
Out[2]: {'e', 'h', 'l', 'o'}

In [3]: food = ['DAIRY', 'DAIRY', 'PRODUCE', 'PRODUCE', 'PRODUCE', 'MEAT']
In [4]: set(food)
Out[4]: {'DAIRY', 'MEAT', 'PRODUCE'}
  • A set is an iterable object
  • You may also be asking yourself, "Wouldn't it be great if there were a way to figure out how many times within a collection a particular value appears?" And the answer is - it would be great! And so there is! Iterables have a .count(VAL) method that you can use:
In [1]: nums = [1, 2, 3, 4, 5, 2, 4, 2]
In [2]: nums.count(2)
Out[2]: 3

In [3]: word = "hello"
In [4]: word.count("l")
Out[4]: 2

In [5]: state = "Mississippi"

In [6]: state.count("s")
Out[6]: 4

In [7]: state.count("ss")
Out[7]: 2

In [8]: state.count("sip")
Out[8]: 1

In [33]: food = ['DAIRY', 'DAIRY', 'PRODUCE', 'PRODUCE', 'PRODUCE', 'MEAT']

In [34]: food.count("PRODUCE")
Out[34]: 3

CarrotBoxes

  • You may be asking yourself, "Wouldn't it be great if there were a way to figure out where in a collection a particular value appears?" And the answer is - it would be great! And so there is! Iterables have a .index(VAL) method that you can use; note that it will only give the index of the first entry in the collection that matches the VAL:
In [1]: nums = [1, 2, 3, 4, 5, 2, 4, 2]
In [2]: nums.index(2)
Out[2]: 1

In [3]: word = "hello"
In [4]: word.index("l")
Out[4]: 2

In [5]: state = "Mississippi"

In [6]: state.index("s")
Out[6]: 2

In [7]: state.index("ss")
Out[7]: 2

In [8]: state.count("sip")
Out[8]: 5

In [33]: food = ['DAIRY', 'DAIRY', 'PRODUCE', 'PRODUCE', 'PRODUCE', 'MEAT']

In [34]: food.index("PRODUCE")
Out[34]: 2

MorselikeCode

If only we had done something similar to this in class... Wait!

Pikachu

  • There are several ways to tackle this problem! Try to think of two different methods and evaluate them for yourself before writing the code.
  • Be careful how you process things! "pkai" and "chpiu" should both yield NO, for instance, so you can't just start looking for and removing instances of "pi," "ka," and "chu."

Individual Lab Report

  • The details below will also help with the Gradescope assignments.
  • Be sure to put the appropriate version of the honor code -- if you use the examples from Pundit, the original author is either DukeEgr93 or Michael R. Gustafson II depending on how you want to cite things.
  • Note that you will need to add plt.ion() after you import matplotlib.pyplot to make sure your codes interactively update.

Chapra 2.15

  • Use fig.set_size_inches(6, 4, forward=True) to make the graph the correct size.
  • To see all the colormaps, after importing the cm group just type
help(cm)
to see the names or go to Colormap Reference to see the color maps - only the ones listed with the help command are actually installed. Avoid the qualitative maps, flag, and prism.

Chapra 2.22

  • Use fig.set_size_inches(6, 8, forward=True) to make the graph the correct size.
  • Don't stare at the top half of the figure too long, or you will get sleepy. Very sleeeeeeepy…
  • Since you are adding two different kinds of axes, you will need to create the figure first and then create two different axis handles by adding subplots to the figure one at a time - a regular one for the top and a 3-D one for the bottom.
  • Don't forget fig.tight_layout()

Chapra 2.27

  • Use fig.set_size_inches(6, 8, forward=True) to make the graph the correct size.

Chapra 2.28

  • Use fig.set_size_inches(6, 8, forward=True) to make the graph the correct size.
  • Recall how to use Python:Logical Masks
  • Here is a demo of using a polar projection:

Sphere

  • It should look like a sphere! Use fig.set_size_inches(6, 6, forward=True) to make the graph the correct size - if the figure window isn't square, the sphere will not actually look...spherical.
  • Don't forget to make it not blue!

Cone

  • It should look like a cone! Use fig.set_size_inches(6, 6, forward=True) to make the graph the correct size
  • Don't forget to use a color map!

Half Disk

  • It should look like a sphere! Use fig.set_size_inches(6, 6, forward=True) to make the graph the correct size - if the figure window isn't square, the sphere will not actually look...spherical.
  • Don't forget to use a different color map!