+ 1

What is it that I'm doing wrong? 😞

Here, take a look at my code; https://code.sololearn.com/cF2Bf2G6Aajc/?ref=app

31st Aug 2018, 10:34 AM
Eyob G. Hagos
Eyob G. Hagos - avatar
8 Answers
+ 3
Change the return statement to print(), yield or something else. As soon as the function returns the first value, the function is done and won't look for more armstrong numbers. Other than that, your code is correct in my opinion
31st Aug 2018, 10:48 AM
Anna
Anna - avatar
+ 2
Depends on what you want to do. For example, you can use a loop to check if a number is a prime number: def isPrime(num): for i in range(2, num): if num % i == 0: return False return True (^^^ this is just an example, there are better ways to do this) As soon as the first divisor is found, you know that the number is not a prime number and you can interrupt the loop (and the function) and return False. So in this case, it definitely makes sense to use a return statement in a loop.
31st Aug 2018, 11:29 AM
Anna
Anna - avatar
+ 1
Maybe start with 2 an not with 0 or 1
31st Aug 2018, 10:49 AM
Paul
Paul - avatar
+ 1
Of course, so silly of me! 😂
31st Aug 2018, 10:50 AM
Eyob G. Hagos
Eyob G. Hagos - avatar
+ 1
Thanks anyways, Anna
31st Aug 2018, 10:51 AM
Eyob G. Hagos
Eyob G. Hagos - avatar
+ 1
Return kills your function replace it with something else.
31st Aug 2018, 10:54 AM
Saithama
+ 1
Okay 👌
31st Aug 2018, 11:31 AM
Eyob G. Hagos
Eyob G. Hagos - avatar
0
@Anna Does that mean that I shouldn't use 'return' in loops?
31st Aug 2018, 11:21 AM
Eyob G. Hagos
Eyob G. Hagos - avatar