Python Programming: An Introduction to Computer Science
Chapter 2 Writing Simple Programs Asyousaw inthepreviouschapter, it is easyto runprogramsthathave alreadybeenwritten.Thehardpart ...
14 CHAPTER2. WRITINGSIMPLEPROGRAMS Fortunately, Suziehasanideatosolve theproblem. Beinga computersciencemajor, shenevergoes anyw ...
2.3.ELEMENTSOFPROGRAMS 15 What is the Celsiustemperature? 100 The temperature is 212.0degrees fahrenheit. YoucanseethatSuzieused ...
16 CHAPTER2. WRITINGSIMPLEPROGRAMS Thesimplestkindofexpressionis aliteral. A literalis usedtoindicatea specificvalue.Inchaos.py ...
2.5.ASSIGNMENTSTATEMENTS 17 print print print , ,..., print , ,..., , Ina nutshell,thesetemplatesshow thataprintstatementconsi ...
18 CHAPTER2. WRITINGSIMPLEPROGRAMS A variablecanbeassignedmany times.It alwaysretainsthevalueofthemostrecentassignment.Here is a ...
2.5.ASSIGNMENTSTATEMENTS 19 2.5.3 SimultaneousAssignment Thereis analternative formoftheassignmentstatementthatallowsustocalcula ...
20 CHAPTER2. WRITINGSIMPLEPROGRAMS Becausetheassignmentis simultaneous,it avoidswipingoutoneoftheoriginalvalues. Simultaneousass ...
2.6.DEFINITELOOPS 21 eachsuccessive valueinthesequence, andthestatementsinthebodyareexecutedonceforeachvalue. Usually, thesequen ...
22 CHAPTER2. WRITINGSIMPLEPROGRAMS Theinterestingandusefulthingaboutloopsis thewaythatthey alterthe“flow ofcontrol”ina program. ...
2.7.EXAMPLEPROGRAM:FUTUREVALUE 23 $100investmentwillgrow to$103inoneyear’s time.How shouldtheuserrepresentanannualizedrateof 3%? ...
24 CHAPTER2. WRITINGSIMPLEPROGRAMS by: John M. Zelle def main(): print "This programcalculates the future value of a 10-yearinve ...
Chapter 3 Computing with Numbers Whencomputerswerefirstdeveloped,they wereseenprimarilyasnumbercrunchers,andthatisstillan import ...
26 CHAPTER3. COMPUTINGWITHNUMBERS aredecimalfractions.Insidethecomputer, wholenumbersandnumbersthathave fractionalcomponentsare ...
3.2.USINGTHEMATHLIBRARY 27 >>> 3.0 * 4.0 12.0 >>> 3 * 4 12 >>> 10.0 / 3.0 3.33333333333 >>> ...
28 CHAPTER3. COMPUTINGWITHNUMBERS root1 = (-b + discRoot)/ (2 * a) root2 = (-b - discRoot)/ (2 * a) print print "The solutionsar ...
3.3.ACCUMULATINGRESULTS:FACTORIAL 29 Python Mathematics English pi π Anapproximationofpi. e e Anapproximationofe. sin(x) sinx Th ...
30 CHAPTER3. COMPUTINGWITHNUMBERS initializationensuresthatfacthasa valueontheveryfirstiteration.Wheneveryouusetheaccumulator pa ...
3.4.THELIMITSOFINT 31 3.4 TheLimitsofInt Sofar, I have talkedaboutnumericdatatypesasrepresentationsoffamiliarnumberssuchasintege ...
32 CHAPTER3. COMPUTINGWITHNUMBERS representa rangeofpositive andnegative integers. Now^2 32 2 ^2 (^31). So,therangeofintegerstha ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf