Python NameError: name 'isAnagram' is not defined
up vote
-4
down vote
favorite
I want to print whether a number is an anagram or not from the user input. I get an error saying nameError.
And this is my code for checking an input for an anagram.
n = input("Enter a long number")
factor = 2
factor_anagram = False
while factor < 10:
if isAnagram(n, factor):
print(n, "is an anagram with factor", factor)
factor_anagram = True
factor += 1
if not factor_anagram:
print("No")
Do I need to create a class? I tried creating an isAnagram class as well. But my implementation did not solve the issue.
python python-3.7
add a comment |
up vote
-4
down vote
favorite
I want to print whether a number is an anagram or not from the user input. I get an error saying nameError.
And this is my code for checking an input for an anagram.
n = input("Enter a long number")
factor = 2
factor_anagram = False
while factor < 10:
if isAnagram(n, factor):
print(n, "is an anagram with factor", factor)
factor_anagram = True
factor += 1
if not factor_anagram:
print("No")
Do I need to create a class? I tried creating an isAnagram class as well. But my implementation did not solve the issue.
python python-3.7
1
Where do you defineisAnagram
?
– Carcigenicate
Nov 18 at 14:24
There is no built-inisAnagram
function. You have to define one your own.
– Austin
Nov 18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 at 14:27
add a comment |
up vote
-4
down vote
favorite
up vote
-4
down vote
favorite
I want to print whether a number is an anagram or not from the user input. I get an error saying nameError.
And this is my code for checking an input for an anagram.
n = input("Enter a long number")
factor = 2
factor_anagram = False
while factor < 10:
if isAnagram(n, factor):
print(n, "is an anagram with factor", factor)
factor_anagram = True
factor += 1
if not factor_anagram:
print("No")
Do I need to create a class? I tried creating an isAnagram class as well. But my implementation did not solve the issue.
python python-3.7
I want to print whether a number is an anagram or not from the user input. I get an error saying nameError.
And this is my code for checking an input for an anagram.
n = input("Enter a long number")
factor = 2
factor_anagram = False
while factor < 10:
if isAnagram(n, factor):
print(n, "is an anagram with factor", factor)
factor_anagram = True
factor += 1
if not factor_anagram:
print("No")
Do I need to create a class? I tried creating an isAnagram class as well. But my implementation did not solve the issue.
python python-3.7
python python-3.7
edited Nov 18 at 14:34
asked Nov 18 at 14:22
Chaite
86
86
1
Where do you defineisAnagram
?
– Carcigenicate
Nov 18 at 14:24
There is no built-inisAnagram
function. You have to define one your own.
– Austin
Nov 18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 at 14:27
add a comment |
1
Where do you defineisAnagram
?
– Carcigenicate
Nov 18 at 14:24
There is no built-inisAnagram
function. You have to define one your own.
– Austin
Nov 18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 at 14:27
1
1
Where do you define
isAnagram
?– Carcigenicate
Nov 18 at 14:24
Where do you define
isAnagram
?– Carcigenicate
Nov 18 at 14:24
There is no built-in
isAnagram
function. You have to define one your own.– Austin
Nov 18 at 14:25
There is no built-in
isAnagram
function. You have to define one your own.– Austin
Nov 18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 at 14:27
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 at 14:27
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
accepted
You are trying to use isAnagram(n, factor) as a built in function like print("xyz"). isAnagram() is not a built in function, so you will have to define it at the top of your code. It can look like this:
def isAnagram(n, factor):
if (whatever comparison needs to be made here):
return True
else:
return False
Now when you call the isAnagram function, either True or False will be returned.
New contributor
add a comment |
up vote
0
down vote
isAnagram does not exist in the default Python library - you have to define it yourself. From the way you're attempting to use it, you want to create a function
def is_anagram(n, factor):
# Your code here
# return True or False
You can then do something like if is_anagram(n, factor):
.
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
You are trying to use isAnagram(n, factor) as a built in function like print("xyz"). isAnagram() is not a built in function, so you will have to define it at the top of your code. It can look like this:
def isAnagram(n, factor):
if (whatever comparison needs to be made here):
return True
else:
return False
Now when you call the isAnagram function, either True or False will be returned.
New contributor
add a comment |
up vote
0
down vote
accepted
You are trying to use isAnagram(n, factor) as a built in function like print("xyz"). isAnagram() is not a built in function, so you will have to define it at the top of your code. It can look like this:
def isAnagram(n, factor):
if (whatever comparison needs to be made here):
return True
else:
return False
Now when you call the isAnagram function, either True or False will be returned.
New contributor
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
You are trying to use isAnagram(n, factor) as a built in function like print("xyz"). isAnagram() is not a built in function, so you will have to define it at the top of your code. It can look like this:
def isAnagram(n, factor):
if (whatever comparison needs to be made here):
return True
else:
return False
Now when you call the isAnagram function, either True or False will be returned.
New contributor
You are trying to use isAnagram(n, factor) as a built in function like print("xyz"). isAnagram() is not a built in function, so you will have to define it at the top of your code. It can look like this:
def isAnagram(n, factor):
if (whatever comparison needs to be made here):
return True
else:
return False
Now when you call the isAnagram function, either True or False will be returned.
New contributor
New contributor
answered Nov 18 at 14:31
Harry Weinman
313
313
New contributor
New contributor
add a comment |
add a comment |
up vote
0
down vote
isAnagram does not exist in the default Python library - you have to define it yourself. From the way you're attempting to use it, you want to create a function
def is_anagram(n, factor):
# Your code here
# return True or False
You can then do something like if is_anagram(n, factor):
.
add a comment |
up vote
0
down vote
isAnagram does not exist in the default Python library - you have to define it yourself. From the way you're attempting to use it, you want to create a function
def is_anagram(n, factor):
# Your code here
# return True or False
You can then do something like if is_anagram(n, factor):
.
add a comment |
up vote
0
down vote
up vote
0
down vote
isAnagram does not exist in the default Python library - you have to define it yourself. From the way you're attempting to use it, you want to create a function
def is_anagram(n, factor):
# Your code here
# return True or False
You can then do something like if is_anagram(n, factor):
.
isAnagram does not exist in the default Python library - you have to define it yourself. From the way you're attempting to use it, you want to create a function
def is_anagram(n, factor):
# Your code here
# return True or False
You can then do something like if is_anagram(n, factor):
.
edited Nov 18 at 14:31
answered Nov 18 at 14:29
Moralous
73111
73111
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361898%2fpython-nameerror-name-isanagram-is-not-defined%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Where do you define
isAnagram
?– Carcigenicate
Nov 18 at 14:24
There is no built-in
isAnagram
function. You have to define one your own.– Austin
Nov 18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 at 14:27