INTRODUCTION TO ENGINEERING

PYTHON



AD

Preface and Table of Contents

This is an introduction to Python for first year engineering students. We are writing this manual for first year engineering students who need to know basic programming. Typically this will be in an introduction to engineering course. The goal is to get you up and running programs as quickly as possible. We will give you all the building blocks to create advanced programs. Programs can be copy and pasted to your editor from the web page. Why Python? Python is capable of infinitely more than what is covered in this tutorial. It is used in web applications, science, and machine learning (artificial intelligence). Even though C++ runs faster, Python development times are much faster. Python is friendly.

We do not cover OOP (Object Oriented Programming) in this manual. OOP adds unnecessary complexity to the first year student. Probably all programs you write as an undergraduate student do not require Object Oriented Programming. Completing Chapter 1 through Chapter 11 are all that are required to write most undergraduate engineering programs. Later chapters are for reference. The final chapters are engineering discipline examples.

The target audience includes first year chemical, mechanical, petroleum, civil, electrical, and industrial engineers.

All programs will be completed on the PyCharm Community interface, which can be installed for free. PyCharm runs on Windows, Linux, and macOS. PyCharm requires 8GB of memory on a Windows computer. This tutorial covers installation on a Windows computer. However the programs run the same once PyCharm is installed.

IMPORTANT: All paragraphs of code are stand alone. You can copy and paste then into PyCharm and have them work. All code has been tested. Two cautions after copy and pasting code from any source.

FIRST: There is always an issue with quote marks when you copy and paste. There are two types of quote marks, depending on the font. Curly quote marks and straight quote marks. Only straight quote marks work in PyCharm. If in doubt retype quote marks in the PyCharm editor.

SECOND: Indentation is significant and important in Python. If the code does not run correctly after copy and pasting to PyCharm, check the indentations.

INTRODUCTION TO ENGINEERING PYTHON:
For First Year Engineering Students
PREFACE AND TABLE OF CONTENTS
CHAPTER 1 - PYTHON INSTALLATION ON WINDOWS
1.1.0 Install Python on Windows
CHAPTER 2 - PYCHARM INSTALLATION ON WINDOWS
2.1.0 Installation of PyCharm on Windows
2.2.0 PyCharm Screen
CHAPTER 3 - SAVING YOUR PROGRAMS
3.1.0 Saving Your Work from PyCharm
CHAPTER 4 - ADDING A PYCHARM PROJECT
4.1.0 Adding a New PyCharm Project
CHAPTER 5 - VARIABLES
5.1.0 Variables
5.2.0 Python Variable Scope
CHAPTER 6 - USING PRINT AND INPUT
6.1.0 Simple Programs Using Print & Input
6.2.0 Print statement
6.3.0 Input statement
CHAPTER 7 - LISTS
7.1.0 Lists in Python
7.2.0 Two Dimensional Lists
CHAPTER 8 - PYTHON LOOPS
8.1.0 For Loop
8.2.0 While Loop
8.3.0 Endless Loops
CHAPTER 9 - PYTHON IF STATEMENTS
9.1.0 If statement
9.2.0 An if-else statement
9.3.0 An if-elif-else statement
9.4.0 Conditional Operators
9.5.0 Logical Operators
CHAPTER 10 - CUSTOM AND BUILTIN FUNCTIONS
10.1.0 Python Custom Functions
10.2.0 Python Builtin Functions
10.3.0 Many of the Builtin Math functions are:
10.4.0 Default Value for a Function Parameter
CHAPTER 11 - BUBBLE SORT
11.1.0 Python Bubble Sort
CHAPTER 12 - PYTHON PLOTTING
12.1.0 A simple Python plot
12.2.0 Installing the Python matplotlib package
12.3.0 Problems installing matplotlib package
12.4.0 Problems running the plot program in PyCharm
12.5.0 The simple Python plot with axis information
CHAPTER 13 - PYTHON FILES
13.1.0 Working with Python files
CHAPTER 14 - PYTHON PRINT FORMATTING
14.1.0 Python printing with the % operator
14.2.0 Python printing with .format
CHAPTER 15 - DICTIONARY, ZIP, COMPREHENSION
15.1.0 Initializing a Python dictionary with zip
15.2.0 Initializing a Python dictionary with comprehension
15.3.0 Create a Python dictionary of keys to numbers
CHAPTER 16 - ARRAYS AND SLICING ARRAYS
16.1.0 Creating arrays
16.2.0 Creating arrays with np.arange().reshape()
16.2.1 Compare linspace and arange
16.3.0 numpy.zeros() and numpy.ones()
16.4.0 Determinants
16.5.0 Transpose of matrix
16.7.0 Add two matrices together
16.8.0 Slicing arrays with Python
CHAPTER 17 - ELECTRICAL ENGINEERING EXAMPLE
17.1.0 Cramer’s & Kirchhoff’s rules
17.1.1 Sample circuit
17.1.2 Circuit with current loops
17.2.0 Equations using Kirchhoff Laws
17.3.0 Finding Determinants for Cramer's rule
17.4.0 Coding matrices
17.5.0 Code for 3 equations, 3 unknowns
CHAPTER 18 - REGRESSION
18.1.0 Regression analysis
18.2.0 Input arrays
18.3.0 Linear regression model
18.4.0 Find the weights
18.5.0 Predict a response
18.6.0 Run the program
18.7.0 Code for plot
CHAPTER 19 - DIFFERENTIAL EQUATION
19.1.0 First order differential equation for a tank drainage problem using Torricelli’s principle 19.2.0 Problem: Drainage from a tank.
19.3.0 Solution
19.4.0 Program
CHAPTER 20 - SECANT METHOD
20.1.0 Secant program for roots of an equation
20.2.0 The math
20.3.0 The program general steps
20.3.1 First Program
20.3.2 Second program
20.4.0 Chemical engineering application
20.4.1 The model





Engineering-Python

SALARSEN.COM
Table of Contents
Ch1-Install Python
Ch2-Install PyCharm
Ch3-Save Work
Ch4-Add Project
Ch5-Variables
Ch6-Print&Input
Ch7-Lists
Ch8-Loops
Ch9-If&Logical
Ch10-Functions
Ch11-Bubble Sort
Ch12-Plotting
Ch13-Files
Ch14-Print Format
Ch15-Dict&Comp&Zip
Ch16-Arrays
Ch17-Electrical
Ch18-Regression
Ch19-Differential
Ch20-Secant