Python Programming: An Introduction to Computer Science
5.5.CHOOSINGCOORDINATES 73 for year in range(1,11): Theexpressionrange(1,11)producesa sequenceofints1–10.Theloopindex variableye ...
74 CHAPTER5. OBJECTSANDGRAPHICS win = GraphWin("Investment Growth Chart", 320, 240) win.setCoords(0.0,0.0, 10.0, 10000.0) Thencr ...
5.6.INTERACTIVEGRAPHICS 75 raw_input("Press<Enter> to quit.") main() Noticehowthecomplex calculationshave beeneliminated.T ...
76 CHAPTER5. OBJECTSANDGRAPHICS win.setCoords(0.0,0.0, 10.0, 10.0) message = Text(Point(5,0.5), "Click on three points") message ...
5.6.INTERACTIVEGRAPHICS 77 from graphics import* def main(): win = GraphWin("Celsius Converter", 300, 200) win.setCoords(0.0,0.0 ...
78 CHAPTER5. OBJECTSANDGRAPHICS Figure5.9:Initialscreenforgraphicaltemperatureconverter Figure5.10:Graphicaltemperatureconverter ...
5.7.GRAPHICSMODULEREFERENCE 79 5.7 GraphicsModuleReference Theexamplesinthischapterhave touchedonmostoftheelementsinthegraphicsm ...
80 CHAPTER5. OBJECTSANDGRAPHICS PointMethods Point(x,y)Constructsa pointhavingthegivencoordinates. getX()Returnsthexcoordinateof ...
5.7.GRAPHICSMODULEREFERENCE 81 TextMethods Text(anchorPoint, string)Constructsa textobjectthatdisplaysthegivenstringcenteredat a ...
82 CHAPTER5. OBJECTSANDGRAPHICS 5.8 Exercises Pickanexampleofaninterestingreal-worldobjectanddescribeit asa programmingobjectby ...
5.8.EXERCISES 83 Anarcherytargetconsistsofa centralcircleofyellowsurroundedbyconcentricringsofred,blue, blackandwhite.Eachringh ...
84 CHAPTER5. OBJECTSANDGRAPHICS 5-clickhouse. Youaretowritea programthatallowstheusertodraw a simplehouseusingfive mouse-clicks ...
Chapter 6 Defining Functions Theprogramsthatwehave writtensofar comprisea singlefunction,usuallycalledmain. We have alsobeen usi ...
86 CHAPTER6.DEFININGFUNCTIONS # Draw a bar for eachsubsequent year for year in range(1,11): principal = principal* (1 + apr) bar ...
6.2.FUNCTIONS,INFORMALLY 87 Obviously, thereis someduplicatedcodeinthisprogram.Forsucha simpleprogram,that’s nota big deal,butev ...
88 CHAPTER6.DEFININGFUNCTIONS Wellnow, thatcertainlyseemstowork,andwe’ve removedsomeoftheduplicationbydefiningthe happyfunction. ...
6.3.FUTUREVALUEWITHA FUNCTION 89 sing("Lucy") print sing("Elmer") 6.3 FutureValuewitha Function. Nowthatyou’ve seenhowdefiningfu ...
90 CHAPTER6.DEFININGFUNCTIONS # Get principaland interest rate principal = input("Enterthe initial principal: ") apr = input("En ...
6.4.FUNCTIONSANDPARAMETERS:THEGORY DETAILS 91 WhenPythoncomestoa functioncall,it initiatesa four-stepprocess. Thecallingprogram ...
92 CHAPTER6.DEFININGFUNCTIONS sing("Fred") print sing("Lucy") def main(): def sing(person): happy() happy() print "Happy birthda ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf