Nov-01-2018, 03:47 AM
Hello,
I am a student and a beginner in learning python coding, and I'm stuck on a self-numbers exercise, where I'm asked to return, from the ListeAuto(N) function, all self-numbers lower or equal to N with N belonging to N*.
But my function returns all the numbers between 1 and N, and I don't understand why :
I am a student and a beginner in learning python coding, and I'm stuck on a self-numbers exercise, where I'm asked to return, from the ListeAuto(N) function, all self-numbers lower or equal to N with N belonging to N*.
But my function returns all the numbers between 1 and N, and I don't understand why :
def ListeAuto(N) : atnb=[] for k in range(1,N+1) : atnb.append(k) sommek=0 for s in (list(int(c) for c in str(k))) : sommek+=k for n in atnb : if n==(sommek+k) : atnb.remove(n) return(atnb)Can you help me finding the solution to my problem ? Thank you in advance.