Day 5
MP2 Kickoff Survey
Please fill out the Reflection and Teaming Survey #1. This survey will help us get a sense of how SoftDes is going for you and help prepare you for the team-based projects that will be coming later in the course.
Linux Fun
In the reading, we learned a variety of useful commands:
- ls
- pwd, cd
- cp, mv
- rm, rmdir
- sudo
- cat, more/less
- wget
- grep
- sed
as well as concepts like:
- tab file name completion
- output redirection with
|
and>
- quitting with Control-c
If any of these look unfamiliar to you, jump back to the reading for a refresher.
You can also run man pwd
to look at the ‘man’ual page for the pwd
command or any other.
The man
command is a great built-in feature but can sometimes be an intimidating information dump.
If you’d like a gentler start, you can check out tldr, which offers a simpler description with examples. Since you have Anaconda, you can install tldr by running:
pip install tldr
Once you’ve got the hang of things and are a power user of these commands, you can switch back to man
to see all the available options you can take advantage of.
We also learned that working in the command line is powerful, but comes with no “undo” functionality. If you’d like to give yourself a bit of a safety net when running commands like rm
, read on to sections 2.11-2.12 to see how to make those commands ask for confirmation first.
Reading Journal Review
In the last two Reading Journals you implemented two very similar functions: middle
and chop
.
These simple functions illustrate a wealth of important (and sometimes tricky) Python concepts:
- mutable vs immutable objects
- pure function vs modifier
- aliasing
- equivalent vs identical object comparison
As we discussed last time, state and stack diagrams are extremely useful for reasoning about code, especially with mutable objects like lists. We can use Python Tutor to visualize the difference between middle and chop.
It’s also probably handy to keep the set of Python list methods in your back pocket.
Iteration
Quick check: Compare and contrast lists and strings
One thing they have in common are that both are “iterables” - we can iterate over all the characters of a string or over all the elements of a list.
Read about iteration design patterns. Some of the concepts covered are a bit more advanced and you don’t need to do everything, but it’s a useful reference. Don’t forget to practice active reading with hands on keyboards trying things out!
This reading is a Jupyter notebook, and the link to the source code is down at the bottom. Download that file and save it locally so you can edit and run cells.
Exercise: cheap is 33 dollars; free is 34!
You walk into a store where each item is priced according to the letters in its name: ‘a’ costs 1 dollar, ‘b’ costs 2, and so on. Write a program that prints a receipt for this wacky store:
bananas $52
rice $35
paprika $72
potato chips $142
------------------------
Total $301
What helper functions would be useful in creating this receipt program? What iteration patterns might each of them use?
Hint: the built-in ‘ord’ and ‘chr’ functions may be useful. If you use these, pay attention to how case, punctuation, and whitespace affect the result.