PYTHON

Welcome to the author’s webpage for **Introduction to Engineering Python: For First Year Engineering Students** by Steve Larsen. This is the simplest and most direct way to learn Python. Python is one of the most popular programming languages. If you are a graduating high school senior, complete the first twelve short chapters. If you are looking at AI, also read Chapters 15 and 16. My beginning tutorials for AI are at https://thesurfdragon.com Follow along with website Chapter 1 and Chapter 2 during the download and installation on Windows. Both chapters were updated January 2024. Use the APPENDIX: for installation of Python and PyCharm on Linux Mint.

You can learn Python for FREE using this website. Download Python, and download PyCharm Community for FREE! Python is the programming language, and PyCharm Community is the user interface where your programs are created.

For First Year Engineering Students

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

APPENDIX: Installation of Python and PyCharm on Linux.

S. A. Larsen started college at a community college in San Diego. Here FORTRAN was learned in an introductory computer class. After one semester he transferred to the University of Oklahoma, School of Petroleum Engineering. Here BASIC was taught in the introduction to engineering class. BASIC was used through out the four year curriculum. Graduated in 1984 with a 3.4 GPA. Attained a Bachelor of Science Degree in Petroleum Engineering. Worked as a petroleum engineer in Anchorage, Alaska; and in Bakersfield, California. Took extension classes in Dallas, Texas.

When Windows 3.1 came on the market, he took adult education classes in the Microsoft suite. Later he studied web development, including Linux webservers. Along the way programs were written in Microsoft VBA, LibreOffice Calc, JavaScript, PHP, and Perl.

But by far the most useful language learned was Python. It is used in many environments, including web development, AI development, and engineering. This prompted the writing of this manual for first year engineering students. Python is useful in math, science, electrical, numerical methods, and finance. Python is user friendly.

Installation of Python, and PyCharm has been updated as of January 2024. These changes occur in Chapter1, Chapter2, and the Appendix.