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

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

Image of the Page - 28 -

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

Text of the Page - 28 -

28 1 TheFirstFewSteps Exercise1.7: Peculiarresults fromdivision Consider the following interactivePythonsession: In [1]: x=2; y=4 In [2]: x/y Out[2]: 0 What is theproblemandhowcanyoufix it? Exercise1.8:Updatevariableatcommandprompt InvokePython interactivelyandperformthe followingsteps. 1. Initializeavariablex to2. 2. Add3 tox. Printout the result. 3. Print out the result ofx + 1*2and(x+1)*2. (Observehowparenthesesmake adifference). 4. Whatvariable type isx? Exercise1.9: Formattedprint toscreen Write a program that defines two variables as x = pi and y = 2. Then let the program compute the product z of these two variables and print the result to the screenas Multiplying 3.14159 and 2 gives 6.283 Filename:formatted_print.py. Exercise1.10:Pythondocumentationandrandomnumbers Writeaprogramthatprintsfourrandomnumberstothescreen.Thenumbersshould bedrawnfromauniformdistributionoverthe interval Ε’0;10/ (0inclusive,10exclu- sive). Find the informationneededfor the task, see forexamplehttp://docs.python. org. Hint Pythonhasamodulerandom that containsa functionby thenameuniform. Filename:drawing_random_numbers.py. OpenAccess This chapter is distributedunder the termsof theCreativeCommonsAttribution- NonCommercial 4.0 International License (http://creativecommons.org/licenses/by-nc/4.0/), which permits any noncommercial use, duplication, adaptation, distribution and reproduction in anymediumor format, as long as you give appropriate credit to the original author(s) and the source, a link isprovided to theCreativeCommons licenseandanychangesmadeare indicated. The images or other third partymaterial in this chapter are included in the work’s Creative Commons license, unless indicated otherwise in the credit line; if suchmaterial is not included in thework’s Creative Commons license and the respective action is not permitted by statutory regulation, users will need to obtain permission from the license holder to duplicate, adapt or reproduce thematerial.
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