Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Page - XVI -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

Page - XVI - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Image of the Page - XVI -

Image of the Page - XVI - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition

Text of the Page - XVI -

xvi Contents 2 A FewMoreSteps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.1 UsingPythonInteractively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.1.1 TheIPythonShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 2.1.2 CommandHistory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.1.3 TABCompletion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 2.2 Variables,ObjectsandExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.2.1 ChooseDescriptiveVariableNames . . . . . . . . . . . . . . . . . . . 41 2.2.2 ReservedWords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 2.2.3 Assignment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 2.2.4 ObjectTypeandTypeConversion . . . . . . . . . . . . . . . . . . . . . 42 2.2.5 AutomaticTypeConversion . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.2.6 OperatorPrecedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 2.2.7 Division—QuotientandRemainder . . . . . . . . . . . . . . . . . . . 45 2.2.8 UsingParentheses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.2.9 Round-OffErrors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.2.10 BooleanExpressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 2.3 NumericalPythonArrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.3.1 ArrayCreationandArrayElements . . . . . . . . . . . . . . . . . . . 47 2.3.2 IndexinganArrayfromtheEnd . . . . . . . . . . . . . . . . . . . . . . 50 2.3.3 IndexOut ofBounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.3.4 CopyinganArray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 2.3.5 SlicinganArray. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.3.6 Two-DimensionalArraysandMatrixComputations . . . . . . 52 2.4 RandomNumbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.5 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56 3 LoopsandBranching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 3.1 TheforLoop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 3.1.1 Example:Printing the5 TimesTable. . . . . . . . . . . . . . . . . . . 59 3.1.2 Characteristicsofa Typical forLoop. . . . . . . . . . . . . . . . . . . 60 3.1.3 CombiningforLoopandArray . . . . . . . . . . . . . . . . . . . . . . . 62 3.1.4 Using therangeFunction . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 3.1.5 Usingbreakandcontinue. . . . . . . . . . . . . . . . . . . . . . . . . . 64 3.2 ThewhileLoop. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 3.2.1 Example:Finding theTimeofFlight. . . . . . . . . . . . . . . . . . . 65 3.2.2 Characteristicsofa Typicalwhile Loop . . . . . . . . . . . . . . . . 66 3.3 Branching(if,elifandelse) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 3.3.1 Example: Judging theWater Temperature . . . . . . . . . . . . . . 68 3.3.2 TheCharacteristicsofBranching. . . . . . . . . . . . . . . . . . . . . . 70 3.3.3 Example:Finding theMaximumHeight . . . . . . . . . . . . . . . . 70 3.3.4 Example:RandomWalk inTwo Dimensions . . . . . . . . . . . . 72 3.4 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 4 Functionsand theWriting ofCode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 4.1 Functions:HowtoWrite Them?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 4.1.1 Example:WritingOurFirst Function . . . . . . . . . . . . . . . . . . 79 4.1.2 Characteristicsofa FunctionDefinition . . . . . . . . . . . . . . . . 80 4.1.3 Functionsand theMainProgram .. . . . . . . . . . . . . . . . . . . . . 82 4.1.4 LocalVersusGlobalVariables . . . . . . . . . . . . . . . . . . . . . . . . 83
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Volume Second Edition
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python 3.6
Volume
Second Edition
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2020
Language
English
License
CC BY 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
356
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python