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















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













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. 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 at 14:34

























asked Nov 18 at 14:22









Chaite

86




86








  • 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














  • 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








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












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.






share|improve this answer








New contributor




Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























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






    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',
      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








      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.






      share|improve this answer








      New contributor




      Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        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.






        share|improve this answer








        New contributor




        Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















          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.






          share|improve this answer








          New contributor




          Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          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








          New contributor




          Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered Nov 18 at 14:31









          Harry Weinman

          313




          313




          New contributor




          Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Harry Weinman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.
























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






              share|improve this answer



























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






                share|improve this answer

























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






                  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 at 14:31

























                  answered Nov 18 at 14:29









                  Moralous

                  73111




                  73111






























                       

                      draft saved


                      draft discarded



















































                       


                      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

                      Costa Masnaga

                      Fotorealismo

                      Sidney Franklin