+ 1
Why am I getting an error If changes the way of sorting the array
1).class Small: def __init__(self,arr): self.arr=arr def func(self): self.arr=sorted(self.arr) return self.arr[0]+self.arr[1] i = Small(list(map(int,input("Enter the values:").split(" ")))) print(i.func()) 2).class Small: def __init__(self,arr): self.arr=arr def func(self): self.arr=self.arr.sort() return self.arr[0]+self.arr[1] i = Small(list(map(int,input("Enter the values:").split(" ")))) print(i.func())
1 Answer
0
This statement:
self.arr=self.arr.sort()
sorts self.arr in place, and then sets self.arr to None.
Just remove "self.arr=" and it should behave like the first version