Class 04 -More lists, Start Strings

First we are going to explore a little bit deeper into range and lists (pdf=range-linspace) and make some fun plots.

Second, we are going to look at strings  (pdf=strings)in more detail.   You can read more about strings here http://www.tutorialspoint.com/python/python_strings.htm  and this website goes into more detail on the formatting we did.  https://mkaz.com/2012/10/10/python-string-format/

VIDEO

Make sure to take your Quiz on Courseworks!

HOMEWORK

Homework 3 Due Next Class (Wednesday September 21, 2022)

  1. Code.org intro course through stage 15 to stay on pace
  2. Write 50-100 letters of nonsense in a string.  But in that nonsense have a secret code that spells your name with every x letter (e.g. every 5th letter).
    1. print the whole string
    2. use slicing to print your name
    3. use slicing to print your name and then make it upper case
  3. Repeat the same thing with a list but only do your first name. This is different as you are using a list.  #2 above uses a string and this uses a list.  It is a subtle difference but make sure to do it correct for each.
    1. Write the list.
    2. Use slicing to write your name
    3. Write your name in reverse using slicing (for this to easily work the last letter of the list needs to be the last letter of your name)
    4. reverse the list
    5. write your name backwards using slicing on the reversed list.
    6. with the list reversed write your name forward with slicing.
  4. Final 10% today.  Practice some more plotting and make the graph at the bottom of the page. You should be able to put together your line plotting and cosine plotting to make it.  The graph below shows cosine.   I am okay with an ugly B.  You will need to create two and only two numpy arrays to make the B if you set all the different coordinates correctly.  But there are many ways to make a B. But as a hint think about how you can define points in the B.
  5. string-and-list-hw grading rubric

My Answers

My secret coded string!
Boerrianion4an6nn09  i  Jkaj.hif ksfMifnasgmi30flbn-lniao238uasdx
My name in the string using slicing!
Brian J. Mailloux
My name in the string all in upper case
BRIAN J. MAILLOUX
The list
[‘B’, ‘o’, ‘e’, ‘r’, ‘r’, ‘i’, ‘a’, ‘n’, ‘i’, ‘o’, ‘n’, ‘4’, ‘a’, ‘n’, ‘6’, ‘n’, ‘n’]
my name using slicing
[‘B’, ‘r’, ‘i’, ‘a’, ‘n’]
my name backwards using slicing
[‘n’, ‘a’, ‘i’, ‘r’, ‘B’]
I reversed the list
[‘n’, ‘n’, ‘6’, ‘n’, ‘a’, ‘4’, ‘n’, ‘o’, ‘i’, ‘n’, ‘a’, ‘i’, ‘r’, ‘r’, ‘e’, ‘o’, ‘B’]
my name backwards using slicing
[‘n’, ‘a’, ‘i’, ‘r’, ‘B’]
my name using slicing
[‘B’, ‘r’, ‘i’, ‘a’, ‘n’]

12 thoughts on “Class 04 -More lists, Start Strings

  1. I found this class very helpful. I used the concepts in my final project. I also found the final 10% a little difficult to do at first but it made me extremely happy after I figured out how to make a B in the graph.

  2. I think the notebooks for this section really helped me start seeing the benefits of using python when compared to excel. I think the brief description of range and linspace in the packet helped me understand the differences between the two functions a bit better. I think it would be beneficial to add a few more questions within the strings packet to help practice the idea of combining and slicing lists before the homework assignment. I think the homework has a good balance of straightforward questions and slightly more difficult ones. Making a B was tricky, but it was a worth it puzzle. I think this was the right time in the course to start giving more advanced problems in the hw to make us start thinking on our own.

  3. I found figuring out this notebook to be very rewarding. However, I think there were a lot of really interesting ways I could have accomplished it by thinking more out-of-the-box than I actually did at the time. I used individual lines to create my ‘B’, and I wish I had realized there were ways to edit it at the time (before I had the skillset I now have at the end of the semester). But overall I thought this class was a great foundation in getting us/me thinking about the range of possibilities for creating figures in python.

  4. Contrary to some of the other comments here, I actually really enjoyed the last 10% of the homework, making the B graph. It was definitely hard and I didn’t use much of what we learned in class, but it gave me a lot of practice in thinking about what it actually was I wanted to do and then googling until I got there. That definitely seems to be a big part of what we’re being taught in this class–that you have to keep trying different things until you get it, so I thought that last 10% was definitely on theme for that and gave me good practice

  5. Here as in other early lessons, I think I would have benefited by being able to refer to short explanations of “string,” “range,” “linspace,” etc. I know we have “np.arange is for wanting a list of integers” and “np.linspace is for wanting evenly spaced numbers” in our “Range and Linspace” packet, but I didn’t have a sense (for example) of linspace being useful for graphing a continuous plot vs. range being useful for graphing a scatter plot. (Also, range doesn’t have to return a list of integers!) Although this class has very effectively taught me to *do* things in Python, I don’t always have the language to *describe* what I’m doing, and we could begin building that vocabulary early in this class.

  6. I found the first 90% of the homework very doable and fun. I also thought it was a great way to teach some foundational aspects that we need for the more complex coding in python. However, I thought for the beginning of the class the last 10% was pretty difficult and I could have benefitted from more hints. I feel that it was difficult for me to get started on it so it was something that I never ended up learning. It wasn’t crucial to python graphs but it would have been a nice trick to know.

  7. I agree with the comments above, I believe that this was an important lesson because it helped me narrow down my understanding of slicing and because it felt cool to accomplish “drawings” on graphs. Prior to this some of the stuff felt like analysis that I could easily figure out how to do on excel but this was the point that started to change throughout the course. 🙂

  8. This lesson made it easy to understand what it really means when you make a string in python and the concepts of slicing and skipping within them. The first part of the assignment was very straight forward and it allowed me to really focus on understanding strings. The bonus portion was a bit of a challenge at first, but after playing around for a little while I got it. I actually like when you give us a challenge without that many instructions/hints because it helps us learn how to problem solve using python.

  9. This class assignment was helpful in learning more about list syntax and splicing/getting certain info from lists. Particularly useful is learning how to skip every two elements in a list as well as reversing a list using the colons. I thought the graph was a little tricky because I spent thinking about how to actually create the B even though I knew how to plot lines, but I eventually got it.

  10. I really liked this specific homework. It engaged that puzzle-solving part of my mind, so I was actually excited to work things out. That being said, I remember being unclear on the fact that the secret code could contain other things, besides lowercase letters (i.e. capitals, periods, numbers etc). Perhaps if that had been made a bit more clear, (i.e. that you can cast anything to a string), I would have picked up on how to get my full name with capitals and an abbreviated middle name sliced out.

  11. I think this is an extremely important lesson. It is important to really master slicing because it will be very useful when you have a large data set but want to select only a few points. It will give you great control over what data points you are actually doing and will make data analysis much easier. I recommend that you really understand this lesson before moving on!

Leave a Reply