1. Python Primer#
Why Python?
Python is extremely popular for scientific computing and data science
Python is a high-level language. Its syntax is more flexible and forgiving.
Many concepts from Python translate to other languages such as Fortran, C/C++, MATLAB, etc.
You will use Python in CBE 30338 (Process Controls) and it is helpful for CBE 30370 (Phase Equilibria and Separations).
IEEE names Python as the top programming language of 2019
More info: https://spectrum.ieee.org/static/interactive-the-top-programming-languages-2019
Python is extremely popular for machine learning and data science
More info: https://github.blog/2019-01-24-the-state-of-the-octoverse-machine-learning/#programming-languages
Chapter Learning Objectives
After studying this notebook, completing the activities, and asking questions in class, you should be able to:
Write pseudocode and comments pursuant to class standards.
Write, debug, and predict the output of 10 to 20 line Python programs that use
for
,while
,if
,elif
, andelse
.Create and manipulate strings in Python.
Create and iterate over lists.
Create and use functions in Python. This includes writing a complete document string.
Explain scope to a classmate. Predict the output of Python code that involves scope rules (similar to activity).
Read text files into Python.
Activities
Note
The distinction between activity types is predominantly for CBE 20258 which has a more formal “flipped” or “first exposure outside the classroom” structure.
This repository contains a collection Python notebooks with embedded activities.
Home Activity
These are very short activities are designed to promote quick mastery.
For each class meeting, you will be assigned one or more notebooks to read completely. We recommend you also work through all of the home activities as part of the reading. We will post any required home activities to Vocareum.
Some activities we plan to revist during tutorial.
Tutorial Activity
We will come back to this activity in tutorial.
During each lecture, we will walk through the notebook. A majority of class time will be dedicated to completing class activities with partners and discussing as a class. It is critical you attempt the home activties before coming to class, otherwise you may not be ready for the class activities.
Class Activity
We will work on these activities with partners and then compile solutions together.
For *CBE 20258, We will use Vocareum to collect and grade almost all Python assignments this semester. We are providing most of the same activities here on this website as a resource for you in future semesters, e.g., in junior/senior lab when you need to do error propagation.
Sections
- 1.1. Welcome to Jupyter Notebooks and Vocareum
- 1.2. Python Basics I: Variables, Strings, and Bugs
- 1.3. Python Basics II: Loopy Logic
- 1.4. Python Basics III: Lists, Dictionaries, and Enumeration
- 1.5. Functions and Scope
- 1.6. Recursion
- 1.7. Pseudocode
- 1.8. High/Low Guess My Number Game
- 1.9. Modules and Files
- 1.10. Linear Algebra with Numpy and Scipy
- 1.11. Visualization with matplotlib
- 1.12. Manipulating Data with Pandas
- 1.13. Functions as Arguments
- 1.14. Testing and Debugging in Python
- 1.15. Preparing Publication Quality Figures in Python