Web-Books
in the Austria-Forum
Austria-Forum
Web-Books
Informatik
Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python
Page - 23 -
  • User
  • Version
    • full version
    • text only version
  • Language
    • Deutsch - German
    • English

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

Image of the Page - 23 -

Image of the Page - 23 - in Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python

Text of the Page - 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
back to the  book Programming for Computations – Python - A Gentle Introduction to Numerical Simulations with Python"
Programming for Computations – Python A Gentle Introduction to Numerical Simulations with Python
Title
Programming for Computations – Python
Subtitle
A Gentle Introduction to Numerical Simulations with Python
Authors
Svein Linge
Hans Petter Langtangen
Publisher
Springer Open
Date
2016
Language
English
License
CC BY-NC 4.0
ISBN
978-3-319-32428-9
Size
17.8 x 25.4 cm
Pages
248
Keywords
Programmiersprache, Informatik, programming language, functional, imperative, object-oriented, reflective
Category
Informatik
Web-Books
Library
Privacy
Imprint
Austria-Forum
Austria-Forum
Web-Books
Programming for Computations – Python