Python Day 14: Scope

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 any 2 numbers in N and stores it in the maximumDifference instance variable.

  1. class Difference:
  2. def __init__(self, a):
  3. self.__elements = a
  4. def computeDifference(self):
  5. sorted_elements = sorted(self.__elements)
  6. self.maximumDifference = abs(sorted_elements[-1] - sorted_elements[0])
  7. # End of Difference class
  8. _ = input()
  9. a = [int(e) for e in input().split(' ')]
  10. d = Difference(a)
  11. d.computeDifference()
  12. print(d.maximumDifference) is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube