ENGR 102 – Fall 2024
Lecture 1
Introduction to course
Welcome to engineering
What is programming?
Why is this the first thing being covered in engineering?
Welcome to ENGR 102!
• A little about your instructor…
Johnathan McKenzie, Ph.D.
2
About myself
Ph.D. in Industrial Engineering
3
Syllabus review
Posted on Canvas
• (See the pdf which corresponds to your section.)
4
How this class works
• ENGR 102 is a 2-credit class:
• 1 hour per week of “lecture” (1 credit)
• 3 hours per week of “lab” (1 credit)
• So, we meet ~4 hours per week:
• About 1 hour each week will be instructor-driven
• About 3 hours each week will be hands-on work (programming, working in
teams, quizzes/exams)
• Attendance is required (except when excused)
• Quizzes and exams occur during meeting times
• Lab work may involve working in teams
• Attendance will affect lab grade
5
Your time expectations (outside of class)
• For every credit hour, you should expect to spend 2-3 hours outside of
class on the subject, weekly
• So, for ENGR 102, you should expect to spend 4-6 hours a week, beyond the
time spent in class
• You should expect to spend time on:
• College of Engineering Homework – based on online video modules (0.5
hours/week)
• Reading (zyBook) (up to 1 hour/week)
• Lab assignments (3-5 hours/week)
• Studying (regularly)
6
Prior programming experience not needed!
7
Data taken from Ritchey sections in Fall 19, 21, 22, 23 semesters (967 students total)
8
9
Why are we studying programming?
• Computer programs are a fundamental tool across all of engineering.
• Computing will be used in your classes (especially engineering classes).
• Computing will be used in your job.
• This will include using programs, modifying programs, and writing programs.
• Even if just using computing programs as a tool, understanding how your
tools work can make you more proficient with them!
10
Why are we studying programming?
• Computing is transforming all of engineering (and every other field).
• Over the last 20 years, computing has revolutionized most of society.
• Internet, social networks, portable/ubiquitous computing (smartphones), data analytics,
etc.
• This trend is likely to continue!
• Many of the recent advancements and current research directions in
engineering are closely tied to computing.
11
Why are we studying programming?
• For some of you, computing will be the central focus of your study.
• Computer Science and Computer Engineering especially
• Several other majors will require additional computing, often as a
fundamental aspect of the field.
• This material will provide a basis for more advanced studies.
12
Why are we studying programming?
• Computer programming is an element of engineering on its own.
• Involves designing and building a solution to solve some problem, or enable
something new to be done.
• Producing software is similar to building other things.
• Involves design, analysis, construction, testing, etc.
• The “material” used to build with is computer code.
• Not all engineering involves physical devices.
• Some fields focus on processes, for instance!
13
Relevant Survey
• In a recent survey of Texas A&M Engineering graduates which asked
them what their job involved, computing was listed more frequently
than every other topic!
• As we prepare you to be engineering leaders for the next decades,
computing skills will be a critical component of your skill set
14
TAMU Courses that Include Programming
• AERO 222 • IDIS 450
• BAEN 201 • ISEN 355
• BMEN 207 • MEEN 357
• CHEN 320 • MMET 410
• Almost all CSCE courses • MSEN 330
• CVEN/EVEN 413 • NUEN 329
• DAEN 300 • OCEN 361
• ECEN 250 • PETE 219
• ESET 269 • And many more!
15
A note on academic honesty
• In the working world,
programmers often use online
resources to help with their
coding.
16
A note on academic honesty
X
• This is not the working world.
• Using any online aid to complete
assignments will be considered
cheating.
• When in doubt, ask your
instructor! X
X
17
A note on ChatGPT
• In a recent study*
• More than half of ChatGPT answers contain incorrect information.
• Many answers are incorrect due to ChatGPT’s incapability to understand the
underlying context of the question being asked.
• The majority of ChatGPT’s code errors are due to applying wrong logic.
• People can correctly discern ChatGPT answers from human answers over 80%
of the time.
• Users overlook incorrect information in ChatGPT answers 39% of the time.
• Don’t rely on ChatGPT in this class
*S. Kabir, D.N. Udo-Imeh, B. Kou, T. Zhang, Is Stack Overflow Obsolete? An Empirical Study of the Characteristics of ChatGPT Answers to Stack Overflow Questions,
Proceedings of the CHI Conference on Human Factors in Computing Systems, May 2024
18
Programming
19
Computer Programming – The Basic Process
• A programmer • A compiler or • When a program
writes interpreter takes is run, the
commands / those commands instructions are
instructions, and converts executed on the
called a program, them to 01010010
computer
for the computer instructions that 10010101
to follow the computer 00101110
can understand 10101011
command 10101010
command 10111101
command 00101000
… 10101000
command 10111…
Computer Machine
Program Instructions
20
The Program
• A program is just a file with programming language text (commands)
in it.
• You can, generally, use any editor you want to write a program.
• Saving as a text file, with the right extension: .py for Python, for instance.
• Some editors are designed to help write programs.
• Can color-code text, give hints, autocomplete, etc.
• We will be using a code editor for this course (VS Code).
21
Compiler vs Interpreter
• The compiler or interpreter translates the program into machine
instructions.
• Think of a compiler as pulling all the information in the program
together, then generating machine instructions.
• Since it can look at the whole program, it can possibly create more optimal
machine instructions.
• The machine instructions are typically saved to a file.
• Think of an interpreter as translating line by line.
• Often, the execution happens as it is interpreted, so there is no intermediate file
saved.
• Python is usually thought of as interpreted.
22
Execution
• For a compiled program, the execution involves “running” the
program.
• Most applications and programs you would run are compiled programs, ready
to be executed.
• For an interpreted program, execution often happens right as the
program is interpreted.
• So, the “program” that is run is just the original program – the machine
instructions might not be saved to a separate file.
• Sometimes, the original program is called a “script”.
23
Programming Languages
• The computer processor understands commands in binary.
• It would be incredibly tedious for people to write significant amounts of code in binary.
• Assembly language provides a direct mapping between the binary commands and
something a person can read.
• Essentially, it just translates from binary to a text representation.
• It is still difficult to write significant amounts of code in this form.
• Programming languages have been developed to help people understand the
instructions given to a computer.
• Although they are still commands to the computer, they are conceptually easier to understand.
• It is usually much easier to comprehend the ideas/purpose of a program in a programming
language.
• It is usually more efficient: one statement in a programming language can replace many
assembly/machine instructions.
24
Programming Languages
• Many languages have been developed.
• Each has its own benefits and drawbacks.
• They have increased and decreased in popularity over time.
• There is no “best” language, though some languages are better than others
for particular tasks.
Python Ruby
C#
C++ Java Ada
COBOL PHP Fortran
Lisp Basic
R
Perl Scheme Matlab Pascal
Javascript
Prolog C
Haskell Scheme
ML
25
Why Python?
• Our main focus in this class will be on Python programming.
• Python is generally considered
• Easy to learn
• Powerful (real applications are written with it)
• Flexible (can be used for many different applications – lots of library support)
• Popular (it is being used more and more)
• Why is it called Python?
• Python gets its name from Monty Python, the British comedy troupe!
26
Python and Math courses
• If you are taking MATH 151, you will probably see some Python.
• Unfortunately, MATH wants to solve equations analytically, so it will
use SymPy – something utterly useless to us.
• DO NOT USE SymPy IN ENGR 102!
• Ideally, you will gain experience in Python in both courses.
• Keep in mind that the topics we cover also have equivalents in many
other languages.
• Learning a new programming language after knowing one is much easier.
27
Getting Set Up
• In the lab portion, you will work on getting the environment set up,
and writing your first programs.
• What you’ll need for our class:
• A Python interpreter (for example: Python 3.12.X)
• A code editor (VS Code)
• We will be using the code editor to develop our programs and execute
them.
28
Getting Set Up
• Click on the Course Materials link (on the Home page of our Canvas).
• Click the link, Getting started with Python, under the Installing
software header.
29
Your First Program
• We will develop more advanced programs as the course goes on, but will start
out with some basic ones.
• The traditional first program people write is called “Hello, World”.
• We’re going to Aggie-fy it!
• We can do this with one line of code:
print("Howdy, World!")
• Note: “print” is a generic term for “display” (usually to the screen), in
contexts like this. It does not mean “print on paper using a printer.”
30
The print statement
Program Output
print("Howdy, World!") Howdy, World!
1
print(1)
The print command instructs For text, the text
the computer to print to print should be
whatever is in the parentheses in quotation
to the screen. marks, single ''
or double "".
Numerical values
can be placed
directly inside.
31
The print statement
Program
print("Area of rectangle is", 5 * 3,
"in^2")
By default, when print items
are separated by a comma, a
space is inserted between the
items when printed.
Output
Area of rectangle is 15
in^2
32
Mathematical Calculations
• Mathematical computations are one of the most common things we’ll do in
this class.
• They are a core part of almost all computer programs.
• Python has support for the basic arithmetic operations.
• + Addition
• - Subtraction
• * Multiplication
• / Division
• Order of operations is enforced.
• So, 4 + 3 * 8 = 28
• Parentheses are also enforced.
• So, (4 + 3) * 8 = 56
33
More Mathematical operations (built in)
• Power: **
• 2 ** 10 = 1024
• Floor Division (division without remainder): //
• 7 // 3 = 2
• Modulus (remainder from division): %
•7 % 3 = 1
• 100 % 10 = 0
34
More Mathematical Functions
• We will add one line to our programs to give us access to additional
mathematical functions.
• We’ll see exactly what this is doing later on.
• For now, put the following line at the top of your program:
from math import *
• Mathematical functions will have a name and parentheses that
enclose the value of which the function is being taken.
• e.g. cos(0) is the cosine of 0
35
Common Mathematical Functions
• Remember to begin your program with:
from math import *
• sqrt(x)square root of x
• cos(x), sin(x), tan(x) trigonometric functions
• acos(x), asin(x), atan(x) inverse trigonometric functions
• log(x), log10(x) logarithm, base e (natural) or base 10
• exp(x) or e**x (e is the base for a natural logarithm)
• There are many more…
• Note: trig functions use radians, not degrees 36
What would the following program print?
from math import *
print("ENGR")
print(((3 ** 3) + 4 * 5) * (sqrt(25) // 2) + (28 %
10))
Output:
ENGR
102.0
37
Why?
((3 ** 3) + 4 * 5) * (sqrt(25) // 2) + (28 % 10)
(( 27 ) + 20 ) * ( 5.0 // 2) + ( 8 )
( 47 ) * ( 2.0 ) + ( 8 )
( 94.0 ) + ( 8 )
102.0
Why is 102.0 printed instead of 102?
We’ll see in 2 weeks!
38
A comment about comments
• Code can also include “comments”.
• These start with a # character.
• Everything on the line after the # is ignored by the computer.
• Comments are there to help users.
• We’ll come back to these in more detail, later.
• For now, we will use comments to write information at the top of our
program, for class purposes.
• To record your name, date, etc.
• Use the headers provided (see Canvas).
39
Problem Solving Tips
Steps to solve a (programming) problem:
1) Understand the problem.
• Read the problem statement!
• Think of similar problems that you have already solved.
2) Make a plan.
• Write pseudocode or comments as your outline.
• Create test cases to check your answers.
3) Execute the plan.
• Write code, run it, test it, and debug it.
4) Review your work.
• Check your output using your test cases.
• Can you think of a better way to solve the problem?
When in doubt, solve the problem by hand first, then write code!
40
First steps
• Install the software (Python and VS Code).
• Write your first “Howdy, World!” program.
• Practice computing mathematical values.
41
Due Dates/Reminders
• Due times are 11:59 pm unless noted otherwise.
Assignment Section 506 Section 207 Section 576
Module 1 Quiz Thursday (8/22) Thursday (8/22) Wednesday (8/21)
(syllabus quiz)
LAB: Submission Sunday (8/25) Sunday (8/25) Monday (8/26)
practice
LAB: Topic 1 Sunday (8/25) Sunday (8/25) Monday (8/26)
42