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’]