limit for a calculation in defining class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • python101
    New Member
    • Sep 2007
    • 90

    #1

    limit for a calculation in defining class

    [code=python]

    class Calulation:
    def __init__(self, a, b, c)
    self._a =a
    self._b =b
    self._c =c

    def __ result
    x=self._a*self. _b - self._b+ self._c
    [/code]
    If I don't want x <0 what would I do, for example if x=-1, then x automatically = 0
  • William Manley
    New Member
    • Mar 2007
    • 56

    #2
    i think this is what you want...:

    [code=python]if x < 0:
    x = 0[/code]

    Comment

    • bartonc
      Recognized Expert Expert
      • Sep 2006
      • 6478

      #3
      Originally posted by python101
      [code=python]

      class Calulation:
      def __init__(self, a, b, c)
      self._a =a
      self._b =b
      self._c =c

      def __ result
      x=self._a*self. _b - self._b+ self._c
      [/code]
      If I don't want x <0 what would I do, for example if x=-1, then x automatically = 0
      Better sample code, next time, please. Here's a clean way to put the test and the assignment on one line:[CODE=python]
      class Calculation:
      def __init__(self, a, b, c):
      self._a = (a, 0)[a < 0]
      self._b = (b, 0)[b < 0]
      self._c = (c, 0)[c < 0]

      def result(self):
      x=self._a*self. _b - self._b+ self._c

      c = Calculation(1, -2, 3)
      print c._b[/CODE]

      Comment

      Working...