Web-Books
im Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Seite - XVI -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

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

Bild der Seite - XVI -

Bild der Seite - XVI - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition

Text der Seite - 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
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python 3.6, Band Second Edition
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python 3.6
Band
Second Edition
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2020
Sprache
englisch
Lizenz
CC BY 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
356
Schlagwörter
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Kategorie
Informatik
Web-Books
Bibliothek
Datenschutz
Impressum
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python