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

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

Bild der Seite - 26 -

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

Text der Seite - 26 -

26 1 TheFirstFewSteps commentsonconstructions that are fastor slow,but themain focusof thisbook is to teachhowtowrite correctprograms,not the fastest possibleprograms. Deletingdatanolongerinuse Pythonhasautomaticgarbagecollection,meaningthat there isnoneedtodelete variables (or objects) that are no longer in use. Python takes care of this by itself. This is opposed to, e.g.,Matlab,where explicit deleting sometimesmay be required. Tip:howtodealwithlonglines Ifastatement inaprogramgets toolong, itmaybecontinuedon thenext lineby inserting a back-slash at the end of the line before proceeding on the next line. However,noblanksmustoccurafter theback-slash! The present introductory book just provides a tiny bit of all the functionality that Pythonhas to offer. An important sourceof information is the official Python documentationwebsite (http://docs.python.org/),whichprovidesaPython tutorial, the Python Library Reference, a Language Reference, andmore. Several excel- lentbooksarealsoavailable(http://wiki.python.org/moin/PythonBooks),butnotso manywith a scientific computing focus. One exception is Langtangen’s compre- hensivebookA Primer onScientific Programmingwith Python, Springer,2016. 1.6 Exercises Exercise1.1:Errormessages Saveacopyof theprogramball.pyandconfirmthat thecopyrunsas theoriginal. You are nowsupposed to introduce errors in the code, one byone. For each error introduced, save and run the program, and comment howwell Python’s response corresponds to the actual error. When you are finishedwith one error, re-set the programtocorrectbehavior(andcheckthat itworks!) beforemovingonto thenext error. a) Insert thewordhelloon theempty lineabove theassignment tov0. b) Removethe# sign in frontof thecomment initial velocity. c) Removethe= sign in theassignment tov0. d) Change the reservedwordprint intopint. e) Change thecalculationofy toy = v0*t. f) Change the lineprint y toprint x. g) Replace the statement y = v0*t - 0.5*g*t**2 by y = v0*t - (1/2)*g*t**2 Filename:testing_ball.py.
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