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

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

Bild der Seite - 27 -

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

Text der Seite - 27 -

1.6 Exercises 27 Exercise1.2:Volumeofacube Writeaprogramthat computes thevolumeV ofacubewith sidesof lengthLD4 cmandprints the result to the screen. BothV andL shouldbedefinedas 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:Areaandcircumferenceofacircle Writeaprogramthatcomputesboth thecircumferenceC and theareaAofacircle with radius r D 2 cm. Let the results beprinted to the screenona single linewith an appropriate text. The variablesC,A and r should all be defined as a separate variables in theprogram. Run theprogramandconfirm that the correct results are printed. Filename:circumference_and_area.py. Exercise1.4:Volumesof threecubes Weare interested in thevolumeV ofacubewith lengthL:V DL3, computed for threedifferentvaluesofL. a) Use thelinspacefunctiontocompute threevaluesofL, equallyspacedon the interval Œ1;3 . b) CarryoutbyhandthecomputationV DL3 ifL isanarraywith threeelements. That is, computeV foreachvalueofL. c) In aprogram,write out the resultVofV = L**3whenL is an arraywith three elements as computedbylinspace in a). Compare the resultingvolumeswith yourhandcalculations. d) MakeaplotofVversusL. Filename:volume3cubes.py. Exercise1.5:Averageof integers Write a program that stores the sum 1C2C3C4C5 in one variable and then createsanothervariablewith theaverageof thesefivenumbers. Print theaverageto the screenandcheck that the result is correct. Filename:average_int.py. Exercise1.6: Interactivecomputingofvolumeandarea a) Compute the volume inExercise 1.2 byusingPython interactively, i.e., do the computationsat thecommandprompt (inaPythonshell aswealso say). Com- parewithwhatyougotpreviously fromthewrittenprogram. b) Do the samealso forExercise1.3.
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