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)
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution 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