Lec Intro Computing
Lec Intro Computing
ENGG1810/9810
Introduction to Engineering Computing
Lecture 1: Introduction to Programming (Python)
COMMONWEALTH OF AUSTRALIA
WARNING
The material in this communication may be subject to copyright under the Act.
Any further reproduction or communication of this material by you may be the
subject of copyright protection under the Act.
Week 5: Functions I
Week 6: Functions II Functions
Week 7: Libraries and Modules I
and Packages
Week 9: Application I
Today’s Lecture
Why Python?
Python is an interpreted high-level general-purpose programming language,
designed by Guido Van Rossum
1989 In December, Van Rossum had been looking for a 'hobby' programming project during Christmas
as his office was closed when he decided to write an interpreter for a "new scripting language”.
He named "Python" to "being in an irreverent mood (and a big fan of Monty Python's Flying Circus)"
1999 Van Rossum submitted a funding proposal to DARPA called "Computer Programming for Everybody",
in which he further defined his goals for Python:
1. Code that is as understandable as plain English
2. An easy and intuitive language just as powerful as major competitors
3. Open source, so anyone can contribute to its development
4. Suitability for everyday tasks, allowing for short development times
ENGG1810/9810
Today’s Lecture
Python Basics
• Python is an interpreter language, which means it executes the code line by line.
• can be typed 1) directly in a shell or 2) stored in a .py file that is read into the shell and evaluated
• Python provides an Python Interpreter: Shell/REPL, for executing a single Python command and
display the result.
62
• Q: Why called Shell?
A: The “Shell” covers/wraps a kernel and allows interacting a user’s input. User
Kernel: A computer program at the core of a computer's operating system and has complete control over everything in the system
HW: hardware (CPU, RAM, Disks, Network Ports)
Python Basics
Python Basics
1. Addition
and press
2. Subtraction
3. Multiplication
We are currently using python 3
but python 2 would produce the
following outcome:
4. Division
ENGG1810/9810
Arithmetic Operators
Operator Operation Example Result
+ Addition 2+1 3
- Subtraction 6.3 – 2.1 4.2
* Multiplication 3*4 12
/ True Division 6/3
oo 2
% Remainder (modulo) 5/3 2
** Exponentiation 2**3 8
// Floor division 20//3 6
ENGG1810/9810
Python:
Objects are Python's abstraction for data. In Python, data are represented by objects or by
relations between objects.
Data Types
Data types are the classification or categorization of data items.
Numbers
• Integers – whole numbers
• Float – numbers with decimal points
• Complex number – real and imaginary numbers
Texts
• String - combination of any characters that appear on keyboard e.g. hello world, Nut3lla#
*Use the type() function to get the type or class name of an object.
ENGG1810/9810
Variables in Python are names given to objects, so that it becomes easy to refer a value.
In other words, a variable points to an object.
ENGG1810/9810
or
ENGG1810/9810
Relational Operators
Operator Operation Example Result
< Less than 3<5 True
> More than 3>5 False
<= Less than or equal to 3 <= 5 True
== Equal/Same as 5 == 3 False
!= Not equal to 5 != 3 True
Important Note!
• Symbol == checks whether the left-side value is equal to the right-side value
• Symbol = assigns value (right-side) to variable (left-side).
ENGG1810/9810
Today’s Lecture
https://docs.python.org/3/library/functions.html
ENGG1810/9810
Editor
0401102345
ENGG1810/9810
arguments
arguments
argument 0 argument 1
• This will return the same output as before but parameter index is stated:
• {0} replaced by value contained in variable code
• {1} replaced by value contained in variable country
• Parameter index can be used if you want to print the argument list in different order
e.g. {1}{0} to print value of country then code.
• Contents outside the curly bracket is printed as it is.
• Parameter index starts with 0.
ENGG1810/9810
THANKS FOR
WATCHING
Good luck in studying