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

Seite - 4 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Bild der Seite - 4 -

Bild der Seite - 4 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text der Seite - 4 -

4 1 TheFirstFewSteps 1.2.1 TheProgram Let us next look at a Pythonprogramfor evaluating this simple formula. Assume theprogramiscontainedas text inafilenamedball.py. The text looksas follows (fileball.py): # Program for computing the height of a ball in vertical motion v0 = 5 # Initial velocity g = 9.81 # Acceleration of gravity t = 0.6 # Time y = v0*t - 0.5*g*t**2 # Vertical position print y Computer programs and parts of programs are typesetwith a blue background in thisbook.Aslightlydarker topandbottombar,asabove, indicates that thecode isacompleteprogramthatcanbe runas it stands.Without thebars, thecode is just a snippetandwill (normally)needadditional lines to runproperly. 1.2.2 DissectionoftheProgram Acomputer program is plain text, as here in the fileball.py,which contains in- structions to the computer. Humans can read the code and understand what the programis capableofdoing,but theprogramitself doesnot trigger anyactionson a computer before another program, thePython interpreter, reads theprogram text and translates this text into specificactions. Youmustlearntoplaytheroleofacomputer AlthoughPythonisresponsibleforreadingandunderstandingyourprogram,it is of fundamental importance thatyoufullyunderstand theprogramyourself. You have toknowthe implicationof every instruction in theprogramandbe able to figureout theconsequencesof the instructions. Inotherwords,youmustbeable toplaytheroleofacomputer. Thereasonforthisstrongdemandofknowledgeis that errors unavoidably, andquite often,will be committed in theprogram text, and to track down these errors, you have to simulate what the computer does with theprogram.Next,weshall explainall the text inball.py in fulldetail. Whenyou runyourprograminPython, itwill interpret the text inyourfile 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 isnotmeantforPythontoread andexecute,but rather forahumanthat reads thecodeand tries tounderstandwhat is going on. Therefore, one rule in Python says thatwhenever Python encounters
zurück zum  Buch Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Titel
Programming for Computations – Python
Untertitel
A Gentle Introduction to Numerical Simulations with Python
Autoren
Svein Linge
Hans Petter Langtangen
Verlag
Springer Open
Datum
2016
Sprache
englisch
Lizenz
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Abmessungen
17.8 x 25.4 cm
Seiten
248
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