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 - 6 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

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

Image of the Page - 6 -

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

Text of the Page - 6 -

6 1 TheFirstFewSteps t = 0.6 # Time y = v0*t - 0.5*g*t**2 # Vertical position print(y) Letusnowexplain thisprogramin fulldetail. Typesettingof Code Computerprograms,andpartsofprograms,are typeset with a blue background in this book. When a complete program is shown, the blue backgroundhasaslightlydarker topandbottombar(asforball.pyhere).Without the bars, the code is just a snippet and will normally need additional lines to run properly. We also use the blue background, without bars, for interactive sessions (Sect.2.1). 1.2.2 DissectingtheProgram A computerprogramlikeball.pycontains instructions to thecomputerwrittenas plain text. Humans can read the code and understand what the program is capable of doing, but the program itself does not trigger any actions on a computer before another program, the Python interpreter, reads the program text and translates this text into specificactions. Youmust learntoplay theroleofacomputer AlthoughPython is responsible for readingandunderstandingyourprogram, it is of fundamental importance that you fully understand the program yourself.Youhavetoknowtheimplicationofeveryinstructionintheprogram andbeable tofigureout theconsequencesof the instructions. Inotherwords, youmustbeable to play the roleofa computer. Oneimportantreasonforthisstrongdemandis thaterrorsunavoidably,and quite often, will be committed in the program text, and to track down these errors,you have to simulate what the computerdoeswith the program.Also, youwilloftenneedtounderstandcodewrittenbyotherpeople.Ifyouareable tounderstandtheir codeproperly,youmaymodifyanduse it as it suitsyou. When you run your program in Python, it will interpret the text in your file line by line, fromthe top, readingeach line fromleft to right.Thefirst line it reads is # Program for computing the height of a ball in vertical motion. This line iswhatwecallacomment.That is, the line isnotmeant forPythontoread andexecute,but rather forahumanthat reads thecodeand tries tounderstandwhat isgoingon.Therefore,onerule inPythonsays thatwheneverPythonencountersthe sign# it takes the rest of the line as a comment. Python then simply skips reading the rest of the line and jumps to the next line. In the code, you see several such comments and probably realize that they make it easier for you to understand (or
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