Starting out with Python - Chapter 1 PPT

download Starting out with Python - Chapter 1 PPT

of 17

Transcript of Starting out with Python - Chapter 1 PPT

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    1/44

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

    STARTING OUT WITH

    ythonythonFirst Editionby

    Tony Gaddis

    Chapter 1Introduction to Computers and Programming

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    2/44

    1-2

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-2

    1.1 Introduction

    • People use computers at…

    – School for writing papers, research, email, online classes, etc.

    – Work for analyzing ata, make presentations, !usinesstransactions, communicating, control machines, etc.

    – "ome for paying !ills, shopping online, communicating, playingcomputer games, etc.

    What are some of the ways youWhat are some of the ways youuse computers?use computers?

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    3/44

    1-#

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#

    1.1 Introduction

    • $e%ices that are computers…

    – &ell Phones

    – iPo s – 'lack!erries – &ar na%igation system ()PS*

    Can you think of some other devicesCan you think of some other devicesthat are computers?that are computers?

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    4/44

    1-+

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-+

    1.1 Introduction•

    &omputers are esigne to o any o! thattheir programs tell them to o.

    • program is a set of instructions that a

    computer follows to perform a task. or e/ample0 icrosoft Wor an o!e Photoshop

    • Programs are commonly referre to as

    software .What software have you used?What software have you used?

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    5/44

    1-

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-

    1.1 Introduction

    • Programmers or Software Developers arethe in i%i uals that create computersoftware.

    • 3hey ha%e the training an skill to esign,create, an test computer programs.

    What are some of the fields inWhat are some of the fields inwhich computer programs arewhich computer programs areused?used?

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    6/44

    1-4

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-4

    1.2 Hardware and Software

    Concept:

    The physical devices that acomputer is made of are referredto as the computer’s hardware.

    The programs that run on acomputer are referred to assoftware.

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    7/44

    1-5

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-5

    1.2 Hardware and Software

    Hardware• 3he physical e%ices that a computer is

    ma e of are referre to as the computer6shardware.• computer is a system of e%ices that

    work together.

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    8/44

    1-7

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-7

    1.2 Hardware and Software

    Hardware &omputer System consists of0 – &entral Processing 8nit (&P8* – ain memory – Secon ary storage – 9nput e%ices – :utput e%ices

    Figure 1-2 3ypical componentsof a computer system

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    9/44

    1-;

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-;

    1.2 Hardware and Software

    Hardware&entral Processing 8nit (&P8*

    3he &P8 is the part of a computer that runs the

    programs.Without a &P8 a computer cannot run software.

    Running or executing a program is the term use whenthe computer performs the tasks that the program tellsit to o.

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    10/44

    1-1<

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-1<

    1.2 Hardware and SoftwareHardware

    =>9 &? Worl 6s first programma!le computer ? 'uilt in 1;+? $esigne to calculate artillery !allistic

    ta!les for the 8.S. rmy? &P8 was 7 feet tall, 19 & computer(courtesy of 8.S. rmy "istoric &omputer 9mages*

    Figure 1-4 la! technicianhol s a mo ernmicroprocessor (photo courtesy of 9ntel&orporation*

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    11/44

    1-11

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-11

    1.2 Hardware and Software

    Hardwareain emory

    ? &onsi ere the computer6s work area

    ? &omputer stores the program that is running as well as theata

    ? &ommonly known as the random-access memory(RAM

    ? $ata is @uickly accesse? A is a %olatile type of memory? 8se for temporary storage? A is erase when computer is turne off

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    12/44

    1-12

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-12

    1.2 Hardware and SoftwareHardwareSecon ary Storage $e%ices

    ? 3ype of memory that can hol ata for long perio s of time.? Programs an important ata are store in secon ary storage

    ? Dis! drive is a common type of secon ary storage

    – Data is stored by magnetically encoding it onto a circular dis – ost computers ha%e an internal isk ri%e – Some ha%e e/ternal isk ri%esB they are use to create !ackup

    copies

    ? "loppy drives recor ata onto a small floppy isk

    – "ol s only a small amount of ata – Slow to access ata – &an !e unrelia!le

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    13/44

    1-1#

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-1#

    1.2 Hardware and Software

    HardwareSecon ary Storage $e%ices

    ? #S$ drives are small e%ices that plug into the computer6suni%ersal serial !us (8S'* port

    – 9t oes not contain a isk – 3he ata is store on flash memory – lso known as memory sticks an flash ri%es – 9ne/pensi%e, relia!le, an small

    ? %ptical devices (&D or D'D – $ata is enco e as a series of pits on the isc6s surface – 8ses laser to enco e the ata – "ol s large amounts of ata – )oo me ium for creating !ackups

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    14/44

    1-1+

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-1+

    1.2 Hardware and SoftwareHardware9nput $e%ices

    ? ny ata the computer collects from people an from other e%icesis calle input.

    ? 3he har ware component that collects the ata is calle an input

    device .? &ommon input e%ices are0 – Cey!oar – ouse – Scanner – icrophone

    – $igital camera

    Can you think of any other input devices?Can you think of any other input devices?

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    15/44

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    16/44

    1-14

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-14

    1.2 Hardware and Software

    Software

    ? =%erything a computer oes is controlle !ysoftware.? 3wo categories of software0

    ? System software

    ? pplication software

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    17/44

    1-15

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-15

    1.2 Hardware and SoftwareSoftwareSystem Software? Programs that control an manage the !asic operations of a

    computer are referre to as system software .? 9nclu es the following types0

    ? %perating System controls the internal operations of the computer6shar ware an manages all of the e%ices connecte to the computer.

    ? #tility Programs perform a specialize task that enhances thecomputer6s operation or safeguar s ata.

    ? Software Developments ools are programs that are use to create,mo ify, an test software.

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    18/44

    1-17

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-17

    1.2 Hardware and SoftwareSoftware

    pplication Software? Programs that people normally spen most of their time running on their

    computers performing e%ery ay tasks are referre to as applicationsoftware .

    ? or e/ample0?

    Wor processing? Sprea sheet? $ata!ase? Presentation

    Can you think of any other applicationCan you think of any other applicationsoftware?software?

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    19/44

    1-1;

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-1;

    1.3 How !om"uters Store Data

    Concept:

    All data that is stored in acomputer is converted tosequences of 0s and 1s.

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    20/44

    1-2<

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-2<

    1.3 How !om"uters Store Data

    ? computer6s memory is i%i e into tiny storage locationsknown as )ytes? :ne !yte represents one num!er ? !yte is i%i e into eight smaller storage locations

    known as )its ()inary digits? 'its are tiny electrical components that can hol either a

    positi%e or a negati%e charge.? positi%e charge is similar to a switch in the on position

    ? negati%e charge is similar to a switch in the off position

    Figure 1-# 3hink of a !yte aseight switches

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    21/44

    1-21

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-21

    1.3 How !om"uters Store Data

    Storing Numbers? 3he positi%e charge or the on position is represente !y

    the igit 1? 3he negati%e charge or the off position is represente !y

    the igit <? 3his correspon s to the !inary num!ering system where

    all numeric %alues are written as a se@uence of

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    22/44

    1-22

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-22

    1.3 How !om"uters Store DataStoring Numbers

    or e/ample0

    Figure 1-11 $etermining the %alueof 1

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    23/44

    1-2#

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-2#

    1.3 How !om"uters Store Data

    Storing Numbers? 3he largest %alue that can !e store in a !yte with

    eight !its is *++ ? 3wo !ytes are use for larger num!ersB ma/imum

    %alue is ,++ +

    Figure 1-13 3wo !ytes use for a large num!er

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    24/44

    1-2+

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-2+

    1.3 How !om"uters Store Data

    Storing Characters? &haracters are store in the computer6s memory as

    !inary num!er ? AS& (American Standard &ode for nformation

    nterchange is a co ing scheme

    Figure 1-14 3he letter is store in memory as the num!er 4

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    25/44

    1-2

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-2

    1.3 How !om"uters Store Data

    Storing Characters? S&99 is a set of 127 numeric co es? S&99 is limite

    ? #nicode is an e/tensi%e enco ing scheme? 9t is compati!le with S&99? 9t represents characters for many languages in the

    worl

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    26/44

    1-24

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-24

    1.3 How !om"uters Store Data

    Advanced Number Storage? 'inary num!ering system can !e use to represent

    only integer num!ers

    ? >egati%e num!ers are enco e using two/scomplement

    ? Aeal num!ers are enco e using floating-pointnotation

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    27/44

    1-25

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-25

    1.3 How !om"uters Store Data

    Other Types of ata? Digital data is ata that is store in !inary? digital device is any e%ice that works with !inary

    ata? $igital images are compose of tiny ots of color

    known as pixels (picture elements? $igital soun is !roken into small pieces known as

    samples

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    28/44

    1-27

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-27

    1.4 How a %rogram &or s

    Concept:

    A computer’s CPU can only

    understand instructions that arewritten in machine language.

    ecause people !nd it verydi"cult to write entire programsin machine language# otherprogramming languages have$een invented.

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    29/44

    1-2;

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-2;

    1.4 How a %rogram &or s

    ? &P8 is the most important component in a computer ? &P8 is not a !rain

    ? &P8 is not smart? &P8 is an electronic e%ice that is esigne to o

    specific things.

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    30/44

    1-#<

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#<

    1.4 How a %rogram &or s

    &P8 is esigne to perform the following operations0? Aea a piece of ata from main memory? ing two num!ers? Su!tracting one num!er from another num!er ? ultiplying two num!ers? $i%i ing one num!er !y another num!er ? o%ing a piece of ata from one memory location

    to another ? $etermining whether one %alue is e@ual to another

    %alue

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    31/44

    1-#1

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#1

    1.4 How a %rogram &or s

    ? &P8 only un erstan s instructions written in machinelanguage

    ? achine language instructions are written in 1s an

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    32/44

    1-#2

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#2

    1.4 How a %rogram &or s

    ? "etch-decode-execute cycle is the term use whenthe &P8 e/ecutes the instructions in a program.? 3he cycle consist of three steps0

    – etch

    – $eco e – =/ecute

    Figure 1-1# 3he fetch- eco e-e/ecute cycle

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    33/44

    1-##

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-##

    1.4 How a %rogram &or s!rom "achine #anguage to Assemb$y#anguage?&omputers only un erstan machine language? achine language is ifficult to write? Assem)ly language uses short wor s that are known asmnemonics? Assem)ler is use to translate an assem!ly languageprogram to machine language

    Figure 1-1' n assem!lertranslates an assem!lylanguage program to amachine language program

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    34/44

    1-#+

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#+

    1.4 How a %rogram &or s

    High%#eve$ #anguages? ssem!ly language is referre to as a low-level language?0igh-level languages allow you to create powerful ancomple/ programs without knowing how the &P8 works,using wor s that are easy to un erstan .

    For example: a, ' S9&, Python, &DD, Au!y, Eisual 'asic

    Do you know of any other high-Do you know of any other high-level computer programminglevel computer programming

    languages?languages?

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    35/44

    1-#

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#

    1.4 How a %rogram &or s

    &ey 'ords( Operators( and Synta): anOverview?1ey words or reserved words ha%e specific meaning anpurpose in the programming language?%perators perform %arious operations on ata?Syntax is a set of rules that must !e strictly followe whenwriting a program?Statements are in i%i ual instructions written in aprogramming language

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    36/44

    1-#4

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#4

    1.4 How a %rogram &or s

    Compi$ers and *nterpreters?3he statements written in a high-le%el language are calle source code or simply code?Source co e is translate to machine language using a compiler or an interpreter ?Syntax error is a mistake such as a0

    ? isspelle wor? issing punctuation character ? 9ncorrect use of an operator

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    37/44

    1-#5

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#5

    1.4 How a %rogram &or s

    Compi$ers and *nterpreters?&ompiler is a program that translates a high-le%ellanguage program into a separate machine languageprogram

    Figure 1-1$ &ompiling a high-le%el program an e/ecuting it

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    38/44

    1-#7

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#7

    1.4 How a %rogram &or s

    Compi$ers and *nterpreters? n interpreter is a program that !oth translates an e/ecutes the instructions in a high-le%el language program

    ?Python language uses an interpreter

    Figure 1-2( =/ecuting a high-le%el program with an interpreter

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    39/44

    1-#;

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-#;

    1.) *sing %yt+on

    Concept:

    The Python interpreter can run

    Python programs that are saved in!les# or can interactively e%ecutePython statements that are typedat the &ey$oard. Python comes witha program named '()* thatsimpli!es the process of writing#e%ecuting# and testing programs.

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    40/44

    1-+<

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-+<

    1.) *sing %yt+on

    The Python *nterpreter ? program that can rea Python programming statementsan e/ecute them is the Python interpreter ?Python interpreter has two mo es0

    – nteractive mo e waits for a statement from thekey!oar an e/ecutes it

    – Script mo e rea s the contents of a file ( Python program or Python script * an interprets eachstatement in the file

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    41/44

    1-+1

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-+1

    1.) *sing %yt+on

    *nterpreter "ode?9n%oke Python interpreter through Win ows or comman line?,,, is the prompt that in icates the interpreter is waiting for aPython statement

    FFF print ‘Python programming is fun!’Python programming is fun!

    FFF

    ?Statements type in interacti%e mo e are not sa%e as a program

    E /E0

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    42/44

    1-+2

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-+2

    1.) *sing %yt+on

    'riting Python Programs and +unningThem in Script "ode?8se a te/t e itor to create a file containing the Python

    statements?Sa%e the file with a .py e/tension?3o run the program0

    FFF python test.pyE /E0

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    43/44

    1-+#

    Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 1-+#

    1.) *sing %yt+on

    The * #, Programming ,nvironment?Integrate De%e opment En%ironment ( * #, *

    – utomatically installe when Python language isinstalle

    – 9t has a !uilt-in te/t e itor – 9$G= e itor colorizes co e

    Figure 1-21 9$G=

  • 8/20/2019 Starting out with Python - Chapter 1 PPT

    44/44