Python NameError: name 'isAnagram' is not defined
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 |
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 '18 at 14:24
There is no built-inisAnagram
function. You have to define one your own.
– Austin
Nov 18 '18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 '18 at 14:27
add a comment |
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 '18 at 14:34
Chaite
asked Nov 18 '18 at 14:22
ChaiteChaite
86
86
1
Where do you defineisAnagram
?
– Carcigenicate
Nov 18 '18 at 14:24
There is no built-inisAnagram
function. You have to define one your own.
– Austin
Nov 18 '18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 '18 at 14:27
add a comment |
1
Where do you defineisAnagram
?
– Carcigenicate
Nov 18 '18 at 14:24
There is no built-inisAnagram
function. You have to define one your own.
– Austin
Nov 18 '18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 '18 at 14:27
1
1
Where do you define
isAnagram
?– Carcigenicate
Nov 18 '18 at 14:24
Where do you define
isAnagram
?– Carcigenicate
Nov 18 '18 at 14:24
There is no built-in
isAnagram
function. You have to define one your own.– Austin
Nov 18 '18 at 14:25
There is no built-in
isAnagram
function. You have to define one your own.– Austin
Nov 18 '18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 '18 at 14:27
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 '18 at 14:27
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 18 '18 at 14:31
Harry WeinmanHarry Weinman
313
313
add a comment |
add a comment |
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 |
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 |
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 '18 at 14:31
answered Nov 18 '18 at 14:29
MoralousMoralous
71111
71111
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 at 14:24
There is no built-in
isAnagram
function. You have to define one your own.– Austin
Nov 18 '18 at 14:25
You don't need to create a class. You need to create a function :D
– Canh
Nov 18 '18 at 14:27