+ 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())

2nd Jan 2022, 7:39 PM
Ravi King
1 Respuesta
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
17th Jul 2022, 5:07 AM
Steve
Steve - avatar