Python Programming: An Introduction to Computer Science

(Nora) #1

Chapter 1


Computers and Programs


Almosteveryonehasuseda computeratonetimeoranother. Perhapsyouhave playedcomputergamesor
useda computertowritea paperorbalanceyourcheckbook.Computersareusedtopredicttheweather,
designairplanes,make movies,runbusinesses,performfinancialtransactions,andcontrolfactories.


Have youeverstoppedtowonderwhatexactlya computeris? Howcanonedeviceperformsomany
differenttasks? Thesebasicquestionsarethestartingpointforlearningaboutcomputersandcomputer
programming.


1.1 TheUniversalMachine.


A moderncomputermightbedefinedas“amachinethatstoresandmanipulatesinformationunderthecon-
trolofa changeableprogram.” Therearetwo key elementstothisdefinition. Thefirstisthatcomputers
aredevicesformanipulatinginformation.Thismeansthatwecanputinformationintoa computer, andit
cantransformtheinformationintonew, usefulforms,andthenoutputordisplaytheinformationforour
interpretation.


Computersarenottheonlymachinesthatmanipulateinformation.Whenyouusea simplecalculatorto
addupa columnofnumbers,youareenteringinformation(thenumbers)andthecalculatoris processingthe
informationtocomputea runningsumwhichis thendisplayed.Anothersimpleexampleis a gaspump.As
youfillyourtank,thepumpusescertaininputs:thecurrentpriceofgaspergallonandsignalsfroma sensor
thatreadstherateofgasflowingintoyourcar. Thepumptransformsthisinputintoinformationabouthow
muchgasyoutookandhow muchmoney youowe.


We wouldnotconsidereitherthecalculatororthegaspumpasfull-fledgedcomputers,althoughmodern
versionsofthesedevicesmayactuallycontainembeddedcomputers.They aredifferentfromcomputersin
thatthey arebuiltto performa single,specifictask.Thisis wherethesecondpartofourdefinitioncomesinto
thepicture:computersoperateunderthecontrolofa changeableprogram.Whatexactlydoesthismean?


Acomputerprogramis a detailed,step-by-stepsetofinstructionstellinga computerexactlywhattodo.
If wechangetheprogram,thenthecomputerperformsa differentsequenceofactions,andhence,performs
a differenttask.It is thisflexibilitythatallowsyourPCtobeatonemomenta wordprocessor, atthenext
momenta financialplanner, andlateron,anarcadegame.Themachinestaysthesame,buttheprogram
controllingthemachinechanges.


Everycomputeris justa machineforexecuting(carryingout)programs.Therearemany differentkinds
ofcomputers.YoumightbefamiliarwithMacintoshesandPCs,butthereareliterallythousandsofother
kindsofcomputersbothrealandtheoretical. Oneoftheremarkablediscoveriesofcomputerscienceis
therealizationthatallofthesedifferentcomputershave thesamepower;withsuitableprogramming,each
computercanbasicallydoallthethingsthatany othercomputercando.Inthissense,thePCthatyoumight
have sittingonyourdeskis reallya universalmachine.It candoanythingyouwantit to,providedyoucan
describethetasktobeaccomplishedinsufficientdetail.Now that’s a powerfulmachine!


1
Free download pdf