+ 2

Optimizing my code to get the smallest divisor of int(n) using lambda

Is there a better way to get the smallest divisor preferably, WITHOUT using a function)? Specifically, I want to get rid of the print(z[0]) statement. Do I even have to create the list in the first place? Thanks! https://code.sololearn.com/cZYLeusGNB46/?ref=app

25th Apr 2018, 8:51 AM
Johannes
Johannes - avatar
2 odpowiedzi
+ 4
x = int(input()) for i in range(2,x+1): if(x%i==0): print(i) break
25th Apr 2018, 11:29 AM
Louis
Louis - avatar
8th May 2018, 10:18 PM
Maciek
Maciek - avatar