0

Create a function in python where it will collect multiple values in to a function and find out each value is prime or not

def primeornot(*l): for num in l : if num>1: for i in range(2,num): if(num%i)==0: break else: print(num,"is prime number") return print(primeornot(3,4,5,7,11,12)) But it is showing only 3 is a prime number....i want that to execute all the prime numbers among that

22nd Jun 2021, 10:26 AM
Ninja
Ninja - avatar
4 odpowiedzi
+ 5
change the call to return with a break statement. When you return inside of a function, that function ends. AND no need to call print(primeornot(...)) because inside the function you have calls to print. so just: primeornot(...) will be acceptable and it won't print None. https://code.sololearn.com/c6AnM39xIL6M/?ref=app
22nd Jun 2021, 10:31 AM
Slick
Slick - avatar
0
Tq
22nd Jun 2021, 10:41 AM
Ninja
Ninja - avatar
0
But function should have return know must and should then here in this code we didnt mentioned return
22nd Jun 2021, 2:15 PM
Ninja
Ninja - avatar
0
It SHOULD do whatever it's gotta do to give the correct or percieved output. That's what it does
22nd Jun 2021, 3:12 PM
Slick
Slick - avatar