Find answers, ask questions, and connect with our <br>community around the world.

Home Forums Scientific computing with Python assignment on python

  • assignment on python

    Posted by Premkumar Murugesan on February 21, 2024 at 6:07 pm

    Hi I am trying to find factorial for a number using class methods, but am not getting answer

    can anyone explain what is the problem in my code


    class mathutils():

    def __init__(a,x):


    def fact(a,y):


    while (a.fac>1):



    return b

    c=int(input(“enter the number “))




    enter the number 5
    <__main__.mathutils object at 0x000001C750328710>
    Rahul replied 3 months, 3 weeks ago 2 Members · 2 Replies
  • 2 Replies
  • Premkumar Murugesan

    February 21, 2024 at 6:09 pm
  • Rahul

    February 23, 2024 at 6:37 am

    Hi Premkumar.
    Though you have created a constructor for the mathutils function, you have not created an object for the class, using the input ‘c’. This was the reason for the error.
    Also, mathutils is a library in Python and it is recommended to not use similar names as it will create issues in debugging and understandability of the code when you work on larger projects. Another convention is to use the variable name as ‘self’ instead of ‘a’ to reference variables and functions of the same class. It is not a keyword, but a convention which may be useful when writing larger or more complex code. Please see the modified code attached.

    Best regards

Log in to reply.

error: Content is protected !!