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

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

Bild der Seite - 23 -

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

Text der Seite - 23 -

1.5 MoreBasicConcepts 23 as the answer usually involves extensiveknowledgeof the applicationarea.We will therefore limitour testing to theverificationpart. 1.5.9 InputData Computerprogramsneeda set of inputdata and thepurpose is touse thesedata to computeoutputdata, i.e., results. In thepreviousprogramwehave specified input data in termsofvariables. However,oneoftenwants toget the input throughsome dialogwith theuser. Here is one examplewhere theprogramasks aquestion, and theuserprovidesananswerby typingon thekeyboard: age = input(’What is your age? ’) print "Ok, so you’re half way to %d, wow!" % (age*2) So,afterhavinginterpretedandrunthefirst line,Pythonhasestablishedthevariable age and assigned your input to it. The second line combines the calculation of twice the agewith amessage printed on the screen. Try these two lines in a little test programtosee foryourselfhowitworks. Theinput function is useful for numbers, lists (Chapter 2), and tuples (Chap- ter2). Forpure text, theusermusteitherenclose the input inquotes,or theprogram mustuse theraw_input function instead: name = raw_input(’What is your name? ’) Thereareotherwaysofprovidinginputtoaprogramaswell,e.g.,viaagraphical interface (asmany readerswill beused to) or at the command line (i.e., as param- eters succeeding, on the same line, the command that starts theprogram). Reading datafromafile isyetanotherway. Logically,what theprogramproduceswhenrun, e.g. aplotorprintout to the screenorafile, is referred toasprogramoutput. 1.5.10 SymbolicComputations Even though themain focus in this book is programming of numericalmethods, there are occasionswhere symbolic (also called exactoranalytical) operationsare useful.Doingsymboliccomputationsmeans,asthenamesuggests, thatwedocom- putationswith the symbols themselves rather thanwith the numerical values they could represent. Let us illustrate the difference between symbolic and numerical computationswitha little example.Anumericalcomputationcouldbe x = 2 y = 3 z = x*y print z whichwillmake thenumber6appearonthescreen.Asymboliccounterpartof this codecouldbe
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