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

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

Image of the Page - 45 -

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

Text of the Page - 45 -

2.7 Exercises 45 c) Now let the statement v0 = 5 inside the function y have an indent of three spaces (while the remaining two linesof the functionhave four). d) Removethe left parenthesis in thefirst statementdef y(t): e) Change the first line of the functiondefinition fromdef y(t): todef y():, i.e., removetheparametert. f) Change thefirstoccurrenceof thestatementprint y(time) toprint y(). Filename:errors_colon_indent_etc.py. Exercise2.2:Compare integersaandb Explainbriefly, inyourownwords,what the followingprogramdoes. a = input(’Give an integer a: ’) b = input(’Give an integer b: ’) if a < b: print "a is the smallest of the two numbers" elif a == b: print "a and b are equal" else: print "a is the largest of the two numbers" Proceedbywriting theprogram,andthenrunita fewtimeswithdifferentvalues foraandb to confirmthat itworksas intended. Inparticular, choosecombinations foraandb so that all threebranchesof theifconstructionget tested. Filename:compare_a_and_b.py. Exercise2.3: Functions forcircumferenceandareaofacircle Writeaprogramthattakesacircleradiusrasinputfromtheuserandthencomputes the circumferenceCandareaAof the circle. Implement the computationsofC and A as two separate functions that each takesr as input parameter. PrintC andA to thescreenalongwithanappropriate text. Runtheprogramwith r D1andconfirm thatyouget the right answer. Filename:functions_circumference_area.py. Exercise2.4: Function forareaofarectangle Write a program that computes the areaA D bc of a rectangle. The values of b and c should be user input to the program. Also, write the area computation as a function that takes b and c as input parameters and returns the computed area. Let the programprint the result to screen alongwith an appropriate text. Run the programwithbD2andcD3 to confirmcorrectprogrambehavior. Filename:function_area_rectangle.py. Exercise2.5:Areaofapolygon One of themost importantmathematical problems through all times has been to find the areaof apolygon, especially because real estate areas oftenhad the shape of polygons, and it was necessary to pay tax for the area. We have a polygon as depictedbelow.
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