Title | Ch04 - Michael A. Bauer |
---|---|
Author | Jake Thorburn |
Course | Computer science |
Institution | The University of Western Ontario |
Pages | 84 |
File Size | 2.9 MB |
File Type | |
Total Downloads | 121 |
Total Views | 168 |
Michael A. Bauer...
Chapter4:Loops
ChapterGoals • Toimplementwhileandforloops • Tohand‐tracetheexecutionofaprogram • Tobecomefamiliarwithcommonloopalgorithms • Tounderstandnestedloops • Toimplementprogramsthatreadandprocessdatasets • Touseacomputerforsimulations Inthischapter,youwilllearnaboutloopstatementsinPython,aswell astechniquesforwritingprogramsthatsimulateactivitiesinthereal world.
9/5/2019
2
Contents • Thewhile loop • ProblemSolving:Hand‐Tracing(HW) • Application:ProcessingSentinels • ProblemSolving:Storyboards(HW) • CommonLoopAlgorithms • Thefor loop • Nestedloops • ProcessingStrings • Application:RandomNumbersandSimulation • ProblemSolving:SolveaSimplerProblemFirst
9/5/2019
3
Thewhile Loop
9/5/2019
4
Thewhil whil while e Loop • Examplesofloopapplications • Calculatingcompoundinterest • Simulations,eventdrivenprograms • Drawingtiles… • Compoundinterestalgorithm(Chapter1)
Steps
9/5/2019
5
Planningthewhi whi whille Loop balance=10.0 target=100.0 year=0 rate=0.025 whilebalance...