30 Day code challenge-python
Day 14–Scope
Task
Complete the Difference class by writing the following:
- A class constructor that takes an array of integers as a parameter and saves it to the _elements instance variable.
- A computeDifference method that finds the maximum absolute difference between 2 any numbers in _elements and maximumDifference stores it in the instance variable.
Input Format
The first line contains N, the size of the elements array. The second line has N space-separated integers that describe the _elements array.
Output Format
Print the value of the maximumDifference instance variable.
Explanation
Line 19–20: Calls the class function computeDifference
Line 8–10: The maximum and minimum value is stored in a variable and its difference is found to calculate the maximum sum
Line 11: The value is returned in self.maximumDifference variable
Line 22: Prints the maximum difference
Bonus Tip: abs prints the value irrespective of the magnitude eg: abs(-3) = 3
See you on day 15