Software development

Good practices and tips

Instructors

  • Patricia Ternes - p.ternesdallagnollo@leeds.ac.uk

Part 3.3: Bringing it all together

Training Material:

General Comments

Plan for today

Practical Project

The Problem!

I want a code that returns the area of a circle for a given radius.

Requirements 

  • The main requirement is that no predefined value for π should be used.

  • The value of π (from math/numpy package, for example) can, however, be used to check the accuracy of the result.

  • The result can have a maximum error of 0.01% compared to standard methods (using π from some package and Ï€r²)

Ideation

Brainstorming

Suggested Solution

Code Suggested Steps

The code should:

  1. Receive a radius value

  2. Sort a random x-value inside a line of 2*radius size

  3. Sort a random y-value inside a line of 2*radius size

  4. Check if the (x,y) point is inside or outside the circle

    • If inside, add 1 to a counter

  5. Determine the area by using the proportion of total sorted points and the total number of points inside the circle.

  6. Determine the error between the calculated area and the theoretical area.

    • If the error is lower than the desired error, stop the code.

    • If the error is higher, repeat steps from 2 to 6.