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 - 37 -
  • Benutzer
  • Version
    • Vollversion
    • Textversion
  • Sprache
    • Deutsch
    • English - Englisch

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

Bild der Seite - 37 -

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

Text der Seite - 37 -

1.9 Exercises 37 1.9 Exercises Exercise1.1:ErrorMessages Saveacopyof theprogramball.pyandconfirmthat thecopyrunsas theoriginal. Youarenowsupposedto introduceerrors in thecode,onebyone.Foreacherror in- troduced,save andrun theprogram,andcommenthowwell Python’s responsecor- respondstotheactualerror.Whenyouarefinishedwithoneerror,re-settheprogram tocorrectbehavior (andcheck that it works!)beforemovingon to thenexterror. a) Insert thewordhelloon theempty lineabove theassignment tov0. b) Remove the# sign in frontof thecomment initial velocity. c) Remove the= sign in theassignment tov0. d) Change the reservedwordprint intopint. e) Change the calculationofy toy = v0*t. f) Change the lineprint(y) toprint(x). Filename:testing_ball.py. Exercise1.2:VolumeofaCube Write a programthat computes the volumeV of a cube with sides of lengthL= 4 cm and prints the result to the screen. BothV andL should be defined as separate variables in the program. Run the program and confirm that the correct result is printed. Hint Seeball.py in the text. Filename:cube_volume.py. Exercise1.3:Areaand CircumferenceofaCircle Write a programthat computesboth the circumferenceC and the areaAofa circle withradiusr=2cm.Let theresultsbeprintedto thescreenonasingle linewithan appropriatetext.ThevariablesC,Aandr shouldallbedefinedasseparatevariables in theprogram.Run theprogramandconfirmthat thecorrect resultsareprinted. Filename:circumference_and_area.py. Exercise1.4:VolumesofThreeCubes We are interested in the volumeV of a cube with lengthL:V =L3, computed for threedifferentvaluesofL. a) Inaprogram,use thelinspacefunctiontocomputeandprint threevaluesofL, equallyspacedon the interval [1,3]. b) Carry out, by hand, the computation V = L3 when L is an array with three elements.That is, computeV foreachvalueofL. c) Modifytheprogramina), so that itprintsout theresultVofV = L**3whenL is an array with three elements as computed bylinspace.Compare the resulting volumeswithyourhandcalculations. d) Makea plotofVversusL.
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