boolian logic

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • marc wyburn

    boolian logic

    HI all, I'm a bit stuck with how to work out boolian logic.

    I'd like to say if A is not equal to B, C or D:
    do something.

    I've tried

    if not var == A or B or C:
    and various permutations but can't seem to get my head around it. I'm
    pretty sure I need to know what is calulated first i.e the not or the
    'OR/AND's

    thanks, Marc.
  • Andreas Tawn

    #2
    RE: boolian logic

    if a != b and a != c and a != d:
    doStuff()
    else:
    doOtherStuff()

    Cheers,

    Drea

    >HI all, I'm a bit stuck with how to work out boolian logic.
    >
    >I'd like to say if A is not equal to B, C or D:
    do something.
    >
    >I've tried
    >
    >if not var == A or B or C:
    >and various permutations but can't seem to get my head around it. I'm
    >pretty sure I need to know what is calulated first i.e the not or the
    >'OR/AND's
    >
    >thanks, Marc.

    Comment

    • Aidan

      #3
      Re: boolian logic

      marc wyburn wrote:
      HI all, I'm a bit stuck with how to work out boolian logic.
      >
      I'd like to say if A is not equal to B, C or D:
      do something.
      >
      I've tried
      >
      if not var == A or B or C:
      and various permutations but can't seem to get my head around it. I'm
      pretty sure I need to know what is calulated first i.e the not or the
      'OR/AND's
      >
      thanks, Marc.
      You mean like a ternary operation?
      >>True and 1 or 0
      1
      >>False and 1 or 0
      0

      This of course depends on the 'true' result also being true.. it fails
      if it is false...

      if that's not what you mean, then maybe this is what you want

      if not var==A or not var==B or not var==C:
      # do something

      Comment

      • marc wyburn

        #4
        Re: boolian logic

        On 13 Jun, 10:34, Aidan <awe...@gmail.c omwrote:
        marc wyburn wrote:
        HI all, I'm a bit stuck with how to work outboolianlogic .
        >
        I'd like to say if A is not equal to B, C or D:
           do something.
        >
        I've tried
        >
        if not var == A or B or C:
        and various permutations but can't seem to get my head around it.  I'm
        pretty sure I need to know what is calulated first i.e the not or the
        'OR/AND's
        >
        thanks, Marc.
        >
        You mean like a ternary operation?
        >
         >>True and 1 or 0
        1
         >>False and 1 or 0
        0
        >
        This of course depends on the 'true' result also being true.. it fails
        if it is false...
        >
        if that's not what you mean, then maybe this is what you want
        >
        if not var==A or not var==B or not var==C:
             # do something
        the not var==A or not var==B or not var==C was what I was after.I
        was being too literal with my script and trying not (A or B or C)
        which doesn't work.

        Thanks for the help.

        Comment

        • duncan smith

          #5
          Re: boolian logic

          marc wyburn wrote:
          HI all, I'm a bit stuck with how to work out boolian logic.
          >
          I'd like to say if A is not equal to B, C or D:
          do something.
          >
          I've tried
          >
          if not var == A or B or C:
          and various permutations but can't seem to get my head around it. I'm
          pretty sure I need to know what is calulated first i.e the not or the
          'OR/AND's
          >
          thanks, Marc.
          There's a number of ways of coding it. How about,

          if not var in [A, B, C]:
          #do stuff


          Duncan

          Comment

          • Roel Schroeven

            #6
            Re: boolian logic

            marc wyburn schreef:
            HI all, I'm a bit stuck with how to work out boolian logic.
            >
            I'd like to say if A is not equal to B, C or D:
            do something.
            >
            I've tried
            >
            if not var == A or B or C:
            and various permutations but can't seem to get my head around it. I'm
            pretty sure I need to know what is calulated first i.e the not or the
            'OR/AND's
            if var not in (A, B, C):
            do_something()

            --
            The saddest aspect of life right now is that science gathers knowledge
            faster than society gathers wisdom.
            -- Isaac Asimov

            Roel Schroeven

            Comment

            • cokofreedom@gmail.com

              #7
              Re: boolian logic

              >
              if var not in (A, B, C):
              do_something()
              >
              And this is why I love python.

              Comment

              Working...