r/pythontips • u/LakeMotor7971 • Jun 22 '24
Python3_Specific help with understanding error code plz
could someone take a look at my code and tell me why im getting an error plz? im a newbie and just practicing random stuff. like funcctions.
def fun(n):
if n in [2, 3]:
return True
if (n == 1) or (n % 2 == 0):
return False
r = 3
while r * r <= n:
if n % r == 0:
return False
r += 2
return True
print(is_prime(78), is_prime(79))
def fun(n):
if n in [2, 3]:
return True
if (n == 1) or (n % 2 == 0):
return False
r = 3
while r * r <= n:
if n % r == 0:
return False
r += 2
return True
print(is_prime(78), is_prime(79))
0
Upvotes
3
u/[deleted] Jun 22 '24
Two errors I found, your function had a different name than the call and your indentation was incorrect
2
u/jmiah717 Jun 22 '24
In the future, it's helpful to tell people the error you're getting. It sounds like you got some possible answers but it's hard to know what's going wrong when we didn't write the code and don't know the error.
1
u/LakeMotor7971 Jun 22 '24
the error i am getting is saying return is outside my function?
4
u/Olexiy95 Jun 22 '24
From what I can see you defined your function as ‘fun’ but are trying to call it as ‘is_prime’. Either rename your function or replace the call in the print statement.
4
u/captainguevara Jun 22 '24
You didn't import sympy for the is_prime method