+ 3

Help to slove this error in python 😞😥

A undefined error in this program class insertion: def algo(self,n,elems): for i in range(1,int(n)): j = i while j>=1: if elems[j] < elems[j-1]: temp = elems[j] elems[j] = elems[j-1] elems[j-1] = temp j = j - 1 print('sorted list',elems) def inps(self): elems = [] n = input('enter no of elements : ') for i in range(int(n)): elems.append(int(input())) print('entered list',elems) algo(n,elems) i = insertion() i.inps() i.algorithm()

12th Dec 2018, 2:03 PM
Subrahmanya Mayya
Subrahmanya Mayya - avatar
5 Antworten
+ 9
use "self.algo(n, elems)" and remove last line
12th Dec 2018, 2:07 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 8
Because you didn't remove last line
12th Dec 2018, 2:15 PM
Mert Yazıcı
Mert Yazıcı - avatar
12th Dec 2018, 2:10 PM
Subrahmanya Mayya
Subrahmanya Mayya - avatar
+ 4
Sololearn takes all inputs at one time so you need to separate your inputs with enter button. Your input should be something like this 4 4 2 3 1 or 2 1 2 https://code.sololearn.com/WhiNb9BkJUVC/?ref=app
12th Dec 2018, 4:22 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 1
Mert Yazıcı thanks...😊
13th Dec 2018, 12:47 AM
Subrahmanya Mayya
Subrahmanya Mayya - avatar