SlideShare une entreprise Scribd logo
1  sur  22
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.
BS GIS Instructor: Inzamam Baig
Lecture 1
Fundamentals of Programming
Why are you learning programming?
computers are good at things that humans are not
in order to tell computer how to do a certain task you need to
learn a “computer language”
computer makes our life easier
computers want to helpful but how?
Users vs. Programmers
Users(lay people) see computers as a set of tools - word
processor, spreadsheet, map, to-do list, etc.
Programmers learn the computer “ways” and the computer
language
Programmers have some tools that allow them to build new tools
Programmers sometimes write tools for lots of users
Why be a Programmer?
To get some task done - we are the user and programmer
To produce something for others to use - a programming job
What is Code? Software? A Program?
A sequence of stored instructions
- It is a little piece of our intelligence in the computer
- We figure something out and then we encode it and then give it to someone else
to save them the time and energy of figuring it out
A piece of creativity
Simple representation of computer
hardware
Software
Input
and Output
Devices
Central
Processing
Unit
Main
Memory
Secondary
Memory
Python
Created by Guido van Rossum and first released in 1991
Python is an interpreted, high-level, general-purpose
programming language.
An individual who can speak Python is known as a Pythonista.
Starting python as your first programming
language
In the beginning we will make lots of mistakes
When you make a mistake, the computer will yell “syntax error”
The computer is simple and very fast, but cannot do things by its
own
Your first program
C:UsersTestDesktop>python
Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019,
23:11:46) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for
more information.
>>>print(‘Hello World’)
Python Scripts
Interactive Python is good for experiments and programs of 3-4
lines long.
Most programs are much longer, so we type them into a file and
tell Python to run the commands in the file.
In a sense, we are “giving Python a script”.
As a convention, we add “.py” as the suffix on the end of these
files to indicate they contain Python.
Interactive versus Script
Interactive
- You type directly to Python one line at a time and it responds
Script
- You enter a sequence of statements (lines) into a file using a text
editor and tell Python to execute the statements in the file
Re Writing first program as a Script
Open your favorite text and type:
print(‘hello world from a script’)
Save file as file_name.py
Open command prompt and change directory to the where you saved
the python file
Type:
python file_name.py
Interpreter vs. Compiler
Python is a high-level language.
The actual hardware inside the Central Processing Unit (CPU)
does not understand any of these high-level languages 1
The CPU understands a language we call machine language2
Interpreted vs. Compiled
An interpreter reads the source code of the program as written by
the programmer, parses the source code, and interprets the
instructions on the fly.
Python is an interpreter1
Interpreted vs. Compiled
A compiler needs to be handed the entire program in a file, and
then it runs a process to translate the high-level source code into
machine language and then the compiler puts the resulting
machine language into a file for later execution.
Python Interpreter
The Python interpreter is written in a high-level language called
“C”.
So Python is a program itself and it is compiled into machine
code
In Windows, the executable machine code for Python itself is
likely in a file with a name like:
C:Pythonpython.exe
Program in a nutshell
Like a recipe or installation instructions, a program is a sequence
of steps to be done in order.
Some steps are conditional - they may be skipped.
Sometimes a step or group of steps is to be repeated.
Sometimes we store a set of steps to be used over and over as
needed several places throughout the program.
Sequential Steps
x = 2
print(x)
x = x + 2
print(x)
Program:
x = 2
print(x)
x = x + 2
print(x)
Output:
2
4
Conditional Steps
Output:
x is smaller
End
Program:
x = 5
if x < 10:
print(' x is smaller ')
if x > 20:
print(' x is bigger ')
print(‘End')
x = 5
x < 10 ?
print(‘x is smaller')
x > 20 ?
print(‘x is bigger')
print(‘End')
Yes
No
No
Yes
Repeated Steps
Output:
5
4
3
2
1
Blastoff!
Program:
n = 5
while n > 0 :
print(n)
n = n – 1
print('Blastoff!')
n > 0 ?
Loops (repeated steps) have iteration variables that change each time through
a loop.
No
print('Blastoff')
Yes
n = 5
print(n)
n = n -1
Python Errors
Syntax errors
Logic errors
Semantic errors
Debugging
Debugging is the process of finding the cause of the error in your
code
Reading
Running
Ruminating
Retreating

Contenu connexe

Tendances

Which is better, Java or Python? And how?
Which is better, Java or Python? And how?Which is better, Java or Python? And how?
Which is better, Java or Python? And how?narendrachinnu
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonJaya Kumari
 
a glance at computer programming
a glance at computer programminga glance at computer programming
a glance at computer programmingRex Wang
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures jabirMemon
 
Compliers and interpreters
Compliers and interpretersCompliers and interpreters
Compliers and interpretersshivasdhtsvmic
 
CS1101 Unit 1 Discussion Assignment.docx
CS1101 Unit 1 Discussion Assignment.docxCS1101 Unit 1 Discussion Assignment.docx
CS1101 Unit 1 Discussion Assignment.docxzend_alvi
 
Introduction to Python Programming - I
Introduction to Python Programming  - IIntroduction to Python Programming  - I
Introduction to Python Programming - IArnab Chakraborty
 
Fundamentals of programming final
Fundamentals of programming finalFundamentals of programming final
Fundamentals of programming finalRicky Recto
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonparadisetechsoftsolutions
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / TranslatorsProject Student
 
Introduction to compiler development
Introduction to compiler developmentIntroduction to compiler development
Introduction to compiler developmentDeepOad
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming ConceptsJussi Pohjolainen
 

Tendances (20)

Python
PythonPython
Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Which is better, Java or Python? And how?
Which is better, Java or Python? And how?Which is better, Java or Python? And how?
Which is better, Java or Python? And how?
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
a glance at computer programming
a glance at computer programminga glance at computer programming
a glance at computer programming
 
Computer Programming - Lecture 1
Computer Programming - Lecture 1Computer Programming - Lecture 1
Computer Programming - Lecture 1
 
Introduction python
Introduction pythonIntroduction python
Introduction python
 
Lecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header FileLecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header File
 
C++ programming languages lectures
C++ programming languages lectures C++ programming languages lectures
C++ programming languages lectures
 
Lecture01 - Fundamental Programming with Python Language
Lecture01 - Fundamental Programming with Python LanguageLecture01 - Fundamental Programming with Python Language
Lecture01 - Fundamental Programming with Python Language
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
Program Logic and Design
Program Logic and DesignProgram Logic and Design
Program Logic and Design
 
Compliers and interpreters
Compliers and interpretersCompliers and interpreters
Compliers and interpreters
 
CS1101 Unit 1 Discussion Assignment.docx
CS1101 Unit 1 Discussion Assignment.docxCS1101 Unit 1 Discussion Assignment.docx
CS1101 Unit 1 Discussion Assignment.docx
 
Introduction to Python Programming - I
Introduction to Python Programming  - IIntroduction to Python Programming  - I
Introduction to Python Programming - I
 
Fundamentals of programming final
Fundamentals of programming finalFundamentals of programming final
Fundamentals of programming final
 
Benefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of pythonBenefits & features of python |Advantages & disadvantages of python
Benefits & features of python |Advantages & disadvantages of python
 
Programming Languages / Translators
Programming Languages / TranslatorsProgramming Languages / Translators
Programming Languages / Translators
 
Introduction to compiler development
Introduction to compiler developmentIntroduction to compiler development
Introduction to compiler development
 
Intro To Programming Concepts
Intro To Programming ConceptsIntro To Programming Concepts
Intro To Programming Concepts
 

Similaire à Python Lecture 1

Cmp2412 programming principles
Cmp2412 programming principlesCmp2412 programming principles
Cmp2412 programming principlesNIKANOR THOMAS
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners Sujith Kumar
 
intro.pptx (1).pdf
intro.pptx (1).pdfintro.pptx (1).pdf
intro.pptx (1).pdfANIKULSAIKH
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2REHAN IJAZ
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming LanguageR.h. Himel
 
Python Tutorial | Python Programming Language
Python Tutorial | Python Programming LanguagePython Tutorial | Python Programming Language
Python Tutorial | Python Programming Languageanaveenkumar4
 
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON Nandakumar P
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythonRanjith kumar
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyTIB Academy
 
Py4 inf 01-intro
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-introIshaq Ali
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installingMohd Sajjad
 
Btech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageBtech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageRai University
 
Diploma ii cfpc u-1 introduction to c language
Diploma ii  cfpc u-1 introduction to c languageDiploma ii  cfpc u-1 introduction to c language
Diploma ii cfpc u-1 introduction to c languageRai University
 
Computer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cppComputer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cppmeharikiros2
 
introduction to c language
 introduction to c language introduction to c language
introduction to c languageRai University
 
Bsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageBsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageRai University
 

Similaire à Python Lecture 1 (20)

Cmp2412 programming principles
Cmp2412 programming principlesCmp2412 programming principles
Cmp2412 programming principles
 
MODULE 1.pptx
MODULE 1.pptxMODULE 1.pptx
MODULE 1.pptx
 
Introduction to python for Beginners
Introduction to python for Beginners Introduction to python for Beginners
Introduction to python for Beginners
 
intro.pptx (1).pdf
intro.pptx (1).pdfintro.pptx (1).pdf
intro.pptx (1).pdf
 
Python_Module_1.pdf
Python_Module_1.pdfPython_Module_1.pdf
Python_Module_1.pdf
 
Programming Fundamentals lecture 2
Programming Fundamentals lecture 2Programming Fundamentals lecture 2
Programming Fundamentals lecture 2
 
Phython Programming Language
Phython Programming LanguagePhython Programming Language
Phython Programming Language
 
Python Tutorial | Python Programming Language
Python Tutorial | Python Programming LanguagePython Tutorial | Python Programming Language
Python Tutorial | Python Programming Language
 
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academyPython tutorial for beginners - Tib academy
Python tutorial for beginners - Tib academy
 
Py4 inf 01-intro
Py4 inf 01-introPy4 inf 01-intro
Py4 inf 01-intro
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Python-00 | Introduction and installing
Python-00 | Introduction and installingPython-00 | Introduction and installing
Python-00 | Introduction and installing
 
Btech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c languageBtech i pic u-1 introduction to c language
Btech i pic u-1 introduction to c language
 
Diploma ii cfpc u-1 introduction to c language
Diploma ii  cfpc u-1 introduction to c languageDiploma ii  cfpc u-1 introduction to c language
Diploma ii cfpc u-1 introduction to c language
 
Computer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cppComputer_Programming_Fundamentals in cpp
Computer_Programming_Fundamentals in cpp
 
introduction to c language
 introduction to c language introduction to c language
introduction to c language
 
Bsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c languageBsc cs i pic u-1 introduction to c language
Bsc cs i pic u-1 introduction to c language
 

Plus de Inzamam Baig

Plus de Inzamam Baig (13)

Python Lecture 8
Python Lecture 8Python Lecture 8
Python Lecture 8
 
Python Lecture 13
Python Lecture 13Python Lecture 13
Python Lecture 13
 
Python Lecture 12
Python Lecture 12Python Lecture 12
Python Lecture 12
 
Python Lecture 11
Python Lecture 11Python Lecture 11
Python Lecture 11
 
Python Lecture 10
Python Lecture 10Python Lecture 10
Python Lecture 10
 
Python Lecture 9
Python Lecture 9Python Lecture 9
Python Lecture 9
 
Python Lecture 7
Python Lecture 7Python Lecture 7
Python Lecture 7
 
Python Lecture 6
Python Lecture 6Python Lecture 6
Python Lecture 6
 
Python Lecture 5
Python Lecture 5Python Lecture 5
Python Lecture 5
 
Python Lecture 4
Python Lecture 4Python Lecture 4
Python Lecture 4
 
Python Lecture 3
Python Lecture 3Python Lecture 3
Python Lecture 3
 
Python Lecture 2
Python Lecture 2Python Lecture 2
Python Lecture 2
 
Python Lecture 0
Python Lecture 0Python Lecture 0
Python Lecture 0
 

Dernier

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 

Dernier (20)

_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 

Python Lecture 1

  • 1. Creative Commons License This work is licensed under a Creative Commons Attribution 4.0 International License. BS GIS Instructor: Inzamam Baig Lecture 1 Fundamentals of Programming
  • 2. Why are you learning programming? computers are good at things that humans are not in order to tell computer how to do a certain task you need to learn a “computer language” computer makes our life easier computers want to helpful but how?
  • 3. Users vs. Programmers Users(lay people) see computers as a set of tools - word processor, spreadsheet, map, to-do list, etc. Programmers learn the computer “ways” and the computer language Programmers have some tools that allow them to build new tools Programmers sometimes write tools for lots of users
  • 4. Why be a Programmer? To get some task done - we are the user and programmer To produce something for others to use - a programming job
  • 5. What is Code? Software? A Program? A sequence of stored instructions - It is a little piece of our intelligence in the computer - We figure something out and then we encode it and then give it to someone else to save them the time and energy of figuring it out A piece of creativity
  • 6. Simple representation of computer hardware Software Input and Output Devices Central Processing Unit Main Memory Secondary Memory
  • 7. Python Created by Guido van Rossum and first released in 1991 Python is an interpreted, high-level, general-purpose programming language. An individual who can speak Python is known as a Pythonista.
  • 8. Starting python as your first programming language In the beginning we will make lots of mistakes When you make a mistake, the computer will yell “syntax error” The computer is simple and very fast, but cannot do things by its own
  • 9. Your first program C:UsersTestDesktop>python Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>>print(‘Hello World’)
  • 10. Python Scripts Interactive Python is good for experiments and programs of 3-4 lines long. Most programs are much longer, so we type them into a file and tell Python to run the commands in the file. In a sense, we are “giving Python a script”. As a convention, we add “.py” as the suffix on the end of these files to indicate they contain Python.
  • 11. Interactive versus Script Interactive - You type directly to Python one line at a time and it responds Script - You enter a sequence of statements (lines) into a file using a text editor and tell Python to execute the statements in the file
  • 12. Re Writing first program as a Script Open your favorite text and type: print(‘hello world from a script’) Save file as file_name.py Open command prompt and change directory to the where you saved the python file Type: python file_name.py
  • 13. Interpreter vs. Compiler Python is a high-level language. The actual hardware inside the Central Processing Unit (CPU) does not understand any of these high-level languages 1 The CPU understands a language we call machine language2
  • 14. Interpreted vs. Compiled An interpreter reads the source code of the program as written by the programmer, parses the source code, and interprets the instructions on the fly. Python is an interpreter1
  • 15. Interpreted vs. Compiled A compiler needs to be handed the entire program in a file, and then it runs a process to translate the high-level source code into machine language and then the compiler puts the resulting machine language into a file for later execution.
  • 16. Python Interpreter The Python interpreter is written in a high-level language called “C”. So Python is a program itself and it is compiled into machine code In Windows, the executable machine code for Python itself is likely in a file with a name like: C:Pythonpython.exe
  • 17. Program in a nutshell Like a recipe or installation instructions, a program is a sequence of steps to be done in order. Some steps are conditional - they may be skipped. Sometimes a step or group of steps is to be repeated. Sometimes we store a set of steps to be used over and over as needed several places throughout the program.
  • 18. Sequential Steps x = 2 print(x) x = x + 2 print(x) Program: x = 2 print(x) x = x + 2 print(x) Output: 2 4
  • 19. Conditional Steps Output: x is smaller End Program: x = 5 if x < 10: print(' x is smaller ') if x > 20: print(' x is bigger ') print(‘End') x = 5 x < 10 ? print(‘x is smaller') x > 20 ? print(‘x is bigger') print(‘End') Yes No No Yes
  • 20. Repeated Steps Output: 5 4 3 2 1 Blastoff! Program: n = 5 while n > 0 : print(n) n = n – 1 print('Blastoff!') n > 0 ? Loops (repeated steps) have iteration variables that change each time through a loop. No print('Blastoff') Yes n = 5 print(n) n = n -1
  • 21. Python Errors Syntax errors Logic errors Semantic errors
  • 22. Debugging Debugging is the process of finding the cause of the error in your code Reading Running Ruminating Retreating