0

how can I rewrite the code using return statement?

https://code.sololearn.com/cx4sXqDpaYOU/?ref=app How can I get the function to return more than one values?

28th Apr 2019, 4:13 PM
Arima Kousei
Arima Kousei - avatar
2 Respostas
+ 3
Instead of printing the values, add them to a list, then return it. def porm(a): lst = [] k = 0 for i in range(1, a + 1 ): for j in range(1, i + 1): if i % j == 0: k = k + 1 if k == 2: lst.append(i) k = 0 return lst print(porm(42)) # [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41]
28th Apr 2019, 4:24 PM
Diego
Diego - avatar
+ 1
ohh I didnt think of that. Thank you very much
28th Apr 2019, 4:39 PM
Arima Kousei
Arima Kousei - avatar