0

Why "None" is also getting printed everytime ?

# This code is to check whether a number is prime or not ? def is_num_prime(x) : for i in range(2,x) : d = x%i if d == 0 : print('num is not prime') break else : print('num is prime') print(is_num_prime(13))

19th Feb 2020, 4:06 PM
Adil Ansari
Adil Ansari - avatar
2 Answers
+ 2
If your function does not have a return statement, it returns None by default. This is the same case. What you are actually doing is passing the return value of is_num_prime to print, which is None. So None is printed. Change print(is_num_prime(13)) to is_num_prime(13)
19th Feb 2020, 4:16 PM
XXX
XXX - avatar
+ 1
I got it. Thanks XXX
19th Feb 2020, 4:24 PM
Adil Ansari
Adil Ansari - avatar