0
Why is my private variable causing me so much trouble in python. Guys pls suggest me changes in my code to make it error free.
My CODE: class Difference: def __init__(self, a): self.__elements = a def computeDifference(self): self.__elements = sorted(self.__elements) def maximumDifference(self): return (self.__elements[-1]-self.__elements[0])
3 Antworten
+ 2
Next time, it would be better, if you put your code in playground and post the link here. That's easier to test for all.
+ 1
Try this:
class Difference:
def __init__(self, a):
self.__elements = a
def computeDifference(self):
return max(self.__elements) - min(self.__elements)
test = [5, 2, 8, 1, 6]
dif = Difference(test)
print(test)
print('differenz',dif.computeDifference())
0
Please specify what are your problems in relation to your variable, so we can help you.