ExercisesΒΆ
Write a fruitful function
sumTo(n)
that returns the sum of all integer numbers up to and including n. SosumTo(10)
would be1+2+3...+10
which would return the value 55. Use the equation (n * (n + 1)) / 2.
Write a function areaOfCircle(r) which returns the area of a circle of radius r. Make sure you use the math module in your solution.
Rewrite the function
sumTo(n)
that returns the sum of all integer numbers up to and including n. This time use the accumulator pattern.
Write a function called
mySqrt
that will approximate the square root of a number, call it n, by using Newton’s algorithm. Newton’s approach is an iterative guessing algorithm where the initial guess is n/2 and each subsequent guess is computed using the formula: newguess = (1/2) * (oldguess + (n/oldguess)).
Write a function called
myPi
that will return an approximation of PI (3.14159...). Use the Leibniz approximation.
Write a function that takes in input 10 numbers and returns the minimum, the sum, the maximum, and the average.
Note
This workspace is provided for your convenience. You can use this activecode window to try out anything you like.