+ 1
What is it that I'm doing wrong? 😞
Here, take a look at my code; https://code.sololearn.com/cF2Bf2G6Aajc/?ref=app
8 Réponses
+ 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
+ 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.
+ 1
Maybe start with 2 an not with 0 or 1
+ 1
Of course, so silly of me! 😂
+ 1
Thanks anyways, Anna
+ 1
Return kills your function replace it with something else.
+ 1
Okay 👌
0
@Anna Does that mean that I shouldn't use 'return' in loops?