Python NameError: name 'isAnagram' is not defined












-4














I want to print whether a number is an anagram or not from the user input. I get an error saying nameError. Error message



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.










share|improve this question




















  • 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
















-4














I want to print whether a number is an anagram or not from the user input. I get an error saying nameError. Error message



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.










share|improve this question




















  • 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














-4












-4








-4







I want to print whether a number is an anagram or not from the user input. I get an error saying nameError. Error message



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.










share|improve this question















I want to print whether a number is an anagram or not from the user input. I get an error saying nameError. Error message



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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 18 '18 at 14:34







Chaite

















asked Nov 18 '18 at 14:22









ChaiteChaite

86




86








  • 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














  • 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








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












2 Answers
2






active

oldest

votes


















0














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.






share|improve this answer





























    0














    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):.






    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      0














      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.






      share|improve this answer


























        0














        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.






        share|improve this answer
























          0












          0








          0






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 18 '18 at 14:31









          Harry WeinmanHarry Weinman

          313




          313

























              0














              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):.






              share|improve this answer




























                0














                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):.






                share|improve this answer


























                  0












                  0








                  0






                  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):.






                  share|improve this answer














                  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):.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 18 '18 at 14:31

























                  answered Nov 18 '18 at 14:29









                  MoralousMoralous

                  71111




                  71111






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                      ComboBox Display Member on multiple fields

                      Is it possible to collect Nectar points via Trainline?