defining class for physic problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #16
    Originally posted by bartonc
    After that, if you don't want the actual error to show, you can:[CODE=python]
    try:
    a = Arrow(1, 2, 3, -4)
    except ArrowError:
    print "bad argurment"[/CODE]
    This is just a bit fancier:[CODE=python]

    class Arrow(object):
    def __init__(self, *args):
    if len(args) != 4:
    raise ArrowError("Wro ng number of args")
    for i, arg in enumerate(args) :
    if arg < 0:
    raise ArrowError("Arg ument #%d must be positive!" %i)[/CODE]

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #17
      Originally posted by python101
      ^_^ my last question on this problem

      I cannot enter float number
      [code=python]
      a=Arrow(10.2,10 ,0,0)
      >>TypeError: this constructor takes no arguments
      [/code]
      how can I fix this
      I tried with __float__(self) but it did not work either
      >>TypeError: this constructor takes no arguments means your __init__() is not defined or defined incorrectly.

      Comment

      • python101
        New Member
        • Sep 2007
        • 90

        #18
        yes, just figured out it ^_^

        Comment

        Working...