0% found this document useful (0 votes)
3 views47 pages

Week-1-MAK

The document outlines the course structure for INS107E Introduction to Programming Languages (Python), including grading policies, class topics, and essential programming concepts. It covers the basics of programming, computer components, programming languages, and the installation of Python and Anaconda. Additionally, it emphasizes the importance of comments in code and provides guidance on program design and flowchart methodology.

Uploaded by

nixak34028
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views47 pages

Week-1-MAK

The document outlines the course structure for INS107E Introduction to Programming Languages (Python), including grading policies, class topics, and essential programming concepts. It covers the basics of programming, computer components, programming languages, and the installation of Python and Anaconda. Additionally, it emphasizes the importance of comments in code and provides guidance on program design and flowchart methodology.

Uploaded by

nixak34028
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

INS107E INTRODUCTION TO

PROGRAMMING LANGUAGES
(PYTHON)
Merve Akbaş Kaplan, Ph.D.
akbasm@itu.edu.tr
Department of Civil Engineering
Room No: 271

2024-25 Spring INS107E Lecture Notes #1 1


About This Class

2024-25 Spring 2
Grading and Attendance Policy

Term Activities Number Grading (%)


Classwork 4-8 15
Midterm Exam 1 35
Final Exam 1 50
Total 100

2024-25 Spring 3
Class Topics
Week Selected Topics
1 Introduction to Python, installing python on personal computer

2 String manipulations

3 Numerical data types and their manipulations

4 Lists, tuples and dictionaries

5 Lists, tuples and dictionaries

6 Input-output, file manipulations.

7 Logical statements and conditionals

– BREAK

8 Logical statements and conditionals

9 Loops

10 Functions

11 Functions

12 Classes and object oriented programming

13 Classes and object oriented programming

14 Scientific calculations and visualization

* Exam date is tentative, you will be notified at least one week prior.

2024-25 Spring 4
What is programming?
▪ Computer Programming is the art of making a computer do what
you want it to do.
▪ It consists of issuing a sequence of commands to a computer to
achieve an objective,
▪ A program (or software) is a set of instructions (commands) that a
computer follows to perform a task,
▪ Hardwares are the physical devices that make up a computer,
▪ Computer is a system composed of several components that all work
together.

2024-25 Spring 5
Computer Language
▪ A computer program is a set of instructions, written in a computer
language.
▪ Syntax rules are strict grammar rules.
▪ Any variation of the rules causes errors (i.e., FATAL ERROR, from
Fortran 77).
▪ An error is called:
➢ a bug (this definition comes from the ancient computer time with huge
computers and real bugs).

▪ Debugging - correcting the errors.

2024-25 Spring 6
Major components of a computer
▪ Typical major components
➢ Central processing unit (CPU)
❖the part of the computer that actually runs programs
➢ Main memory (RAM)
❖where computer stores a program while program is running, and data used by the
program
❖Known as Random Access Memory (RAM)
❖CPU can quickly access data in RAM
❖All gone when computer is turned off (temporary)

2024-25 Spring 7
Major components of a computer
▪ Typical major components
➢ Secondary storage devices
❖ Can keep data persistently (for long periods of time)
❖ Programs are normally stored here and loaded to main memory when needed
❖ Types: Disk drive (Hard disk), solid state drive, flash memory, optical devices
➢ Input and output devices
❖ Input: the data computer collects from people and other devices
❖ Input device: the component that collects the data (i.e. keyboard, mouse, scanner,
camera,…)
❖ Output: data produced by the computer for other people or devices (can be text,
image, audio, or bit stream)
❖ Output device: formats and prints the output (i.e. display, printer, speakers, disk
drive,…)

2024-25 Spring 8
How the data is stored?
▪ All data in a computer is stored in
sequences of “0”s and “1”s
▪ Byte: just enough memory to store a
letter or small number
➢ Divided into eight bits
➢ A bit is an electrical component that can
hold positive or negative charge like an
on/off switch (0 or 1)
➢ The on/off pattern of bits in a byte
❖ represents the data stored

▪ Binary numbering system is used: 2j-1


▪ Byte size limits are 0 and 255

2024-25 Spring 9
Programming Languages
▪ high level (BASIC,
PYTHON, MATLAB,
FORTRAN)
➢ easier to write code
▪ mid level (C, C++)
▪ low level
➢ assembly (not binary)
➢ machine language
(binary)
➢ differs from hardware
to hardware

2024-25 Spring 10
Generations of Languages
▪ 1GL: Machine level languages
▪ 2GL: Assembly languages
▪ 3GL: High level languages, machine
independent, programmer friendly
➢ C, C++, BASIC, Fortran, Pascal, Java,
Python, Ruby, ...
▪ 4GL: Very high level languages
➢ SQL, LabView, Mathematica, SPSS, R,
MATLAB, ...
▪ 5GL: Natural languages
➢Siri, ChatGPT ve Alexa ...
➢ Turkish, English, ...

2024-25 Spring 11
History of Programming Languages
▪ 1950s: First languages ▪ 1980s: Modules & performance
➢Fortran: scientific and engineering ➢ C++: object oriented
➢ MATLAB: scientific calculation
➢COBOL: business problems
▪ 1990s: Internet age
▪ 1960s: Fundamental paradigms
➢ Python, Java, PHP, ...
➢BASIC: educational tool
▪ 2000s: Optimization & parallel
▪ 1970s: Fundamental paradigms computing
➢PASCAL: structured programming ➢ C#, F#, Scala, Go, ...

➢C: hardware independent ▪ 2010s: New trends


➢SQL: database, 4GL ➢ Swift, Elixir, Julia, ...

2024-25 Spring 12
Compilers and Interpreters
▪ Programs written in high-level languages
must be translated into machine language to
be executed
▪ Compiler translates high-level language
program into a separate machine language
program
▪ Interpreter translates and executes
instructions in a high-level language program
➢ Interprets one instruction at a time
➢ No separate machine language program
▪ Syntax error: prevents code from being
translated

2024-25Spring 13
Compilers and Interpreters

2024-25 Spring 14
Some Common Programming Terms
▪ String: sequence of characters that is used as data
▪ Variable: name that represents a value stored in the computer memory (a
variable references the value it represents)
▪ Assignment statement: used to create a variable and make it reference data
(i.e. age = 29)
▪ Math operator: tool for performing calculation ( + , - , * , /, …)
▪ Operands: values surrounding the operator (i.e. 3+6=9 ;the operands are “3”
and “6” )
▪ Function: piece of prewritten code that performs an operation
▪ Argument: data given to a function (i.e. data that is printed to screen)
▪ Comments: notes of explanation within a program (they will not be executed)

2024-25 Spring 15
Some Common Programming Terms

2024-25 Spring 16
Variable
▪ Variable is a name that can represent the data, numbers or strings. (may
change during the execution of the program)
▪ The following expression means that the variable B is ASSIGNED THE
VALUE 8.0 and its stored in MEMORY.
B = 8.0
What is “B” ?

▪ Here the “=” symbol means in most computer languages “IS ASSIGNED” but NOT the algebraic sign “EQUAL TO”.

2024-25 Spring 17
Variable Naming Rules in Python
▪ Rules for naming variables in Python:
➢ Variable name cannot be a Python keyword
➢ Variable name cannot contain spaces
➢ First character must be a letter (a-z & A-Z) or
an underscore (_)
➢ After first character you may use letters, digits,
or underscores
➢ Variable names are case sensitive

▪ Variable name should reflect its use

2024-25 Spring 18
Variable Naming Rules in Python

2024-25 Spring 19
Operators
▪ Operators are used to implement and/or model expressions,
algorithms or equations.
▪ Software processes them by a given hierarchy.
▪ Basic operators
➢ Arithmetic (+, -, *, /)
➢ Relational (==)
➢ Logical (and)

The shortest correct sequence leading to the correct result constitutes


the best or the most efficient program.
2024-25 Spring 20
Operators

2024-25 Spring 21
Statements and Functions
Statements (deyim, bildirim)
Area of a circle (many statement types)
area = PI/4.0*D**2
area = PI/4.0*SQUARE(D)

Libraries of functions
▪ Instructions that are frequently used in the solution of problems
defined by keywords sin(x), max(x)..., etc.

2024-25 Spring 22
Organizing or Planning a Program
▪ So, how should we organize them all?
➢ variables
➢ operators
➢ equations
➢ statements
➢ expressions
➢ functions
➢ arguments
➢…

2024-25 Spring 23
Steps of Program Design
▪ Program design is a must before they are written
▪ Typical steps of programming:
❖Design the program,
❖Write the code,
❖Correct syntax errors,
❖Test the program,
❖Correct logic errors,

2024-25 Spring 24
Flowcharts
▪ A flowchart is a graphical or pictorial representation START
of an algorithm showing the steps involved as well
as the interrelations of these steps in reaching the ...
solution of a problem.
➢ Defines known and unknown variables and constants. ...
➢ Indicates the sequence of steps and decisions, program
operations, principles and equations used. ...

▪ With a flowchart, writing the actual computer


program is an easy translation.
END

2024-25 Spring 25
Flowcharts
▪ The algorithm process is defined by symbols (boxes with specific shapes), which
START
identifies the action or process.
➢ Start, stop or other end points.
➢ Symbols are connected by arrows that controls the flow of the program. ...

➢ These flow lines indicate the direction or sequence in which data flows or the instructions
are executed. ..
➢ Statements in a program execute in the order that they appear (from top to bottom). .

...

END

2024-25 Spring 26
Flowchart Symbols
TERMINATOR START or END of a flowchart

PROCESS Calculations or variable assignments

DECISION Conditional checks in selection and iteration

INPUT &
OUTPUT
Read or print data
2024-25 Spring 27
Flowchart Examples
Perform a sequence Perform actions based Repeat actions
of actions on a condition in a loop

2024-25 Spring 28
Flowchart Methodology
▪ Define the main problem:
An algorithm for washing hands
▪ Start with a simple chart.

▪ Divide the tasks into subtasks.


▪ Repeat, repeat, repeat…
▪ Stop when you feel comfortable.
▪ This way, the program will be
modular, thus, it will be easier to
write, understand, test and debug.

2024-25 Spring 29
Python Interpreter
▪ When you install Python you also install the
Python interpreter
▪ Python interpreter can be used in two modes:
➢ Interactive mode: enter statements on keyboard
➢ Script mode: save statements as a Python script
and then run

▪ Interactive mode
➢ Interpreter is waiting for a Python statement to be
typed
➢ Statements are not saved as a program

▪ Script mode
➢ A set of Python statements are saved in a file
named with a .py extension
➢ To run the file type python filename.py at the
operating system command line

2024-25 Spring 30
How to install Python?
▪ Go to www.python.org

2024-25 Spring 31
How to install Python?
▪ Choose your platform under the Downloads menu, download (about
25 MB, and install; typical next-next installation)

2024-25 Spring 32
How to install Python?
▪ Choose your platform under the Downloads menu, download (about
25 MB, and install (typical next-next installation)
▪ Latest version is 3.13.2

2024-25 Spring 33
How to install Python?
▪ Choose your platform under the Downloads menu, download (about
25 MB, and install (typical next-next installation)

2024-25 Spring 34
How to install Python?
▪ Choose your platform under the Downloads menu, download (about
25 MB, and install (typical next-next installation)

2024-25 Spring 35
How to run Python?
▪ Type python in search tab of your Windows desktop, click on he
Python icon that appears

2024-25 Spring 36
How to run Python?
▪ Yes. That black window is your Python screen.

2024-25 Spring 37
Good Habits as We Begin
▪ Comments in your code help you or someone else understand
➢ What your program does
➢ What a particular line or section of code does
➢ Why you chose to do something a particular way
➢ Anything that might be helpful to know if I am looking at the code later and
trying to understand it!
In Python we use # sign to indicate comments
#My first Python Application
#Created by me!
#Print command displays a message on the screen
print('Hello World')
2024-25 Spring 38
Just a basic statement for displaying text
print('You can use single quotes!')

print("Double quotes is also fine!")

You can use multiple print statements


print('Print statement 1')
print('Print statement 2')

You can also use “\n” to force a new line

print('This is line 1 1\n This is line 2')

2024-25 Spring 39
Just a basic statement for displaying text

Or you can use triple quotes:


print("""This is line 1
This is line 2 """)

2024-25 Spring 40
Is that all?
The open source Anaconda
Distribution is the easiest way to
do Python data science and
machine learning. It includes
hundreds of popular data
science packages and
the conda package and virtual
environment manager for
Windows, Linux, and MacOS.

Conda makes it quick and easy


to install, run, and upgrade
complex data science and
machine learning environments
like scikit-learn, TensorFlow, and
SciPy.
2024-25 Spring 41
How to install ANACONDA?
▪ Go to www.anaconda.com and download the installer

2024-25 Spring 42
How to install ANACONDA?
▪ Download the version compatible with your operating system

2024-25 Spring 43
How to install ANACONDA?
▪ Double click to the downloaded file and install it

2024-25 Springl 44
ANACONDA Navigator

2024-25 Spring 45
2024-25 Spring 46
Matplotlib

Python Core ≡ MATLAB


Numpy SciPy

2024-25 Spring 47

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy