Thread: If statement

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    42
    Rep Power
    2

    If statement


    Hi there, I am having some trouble with an if statement..
    I don't know if I am using the "or" "and" wrong maybe? but I dont get any errors it just doesn't use the if properly..

    I want it to check the following:

    if marginInSEK < float(NegativeMarginThreshold) or marginInSEK > float(ExcessiveMarginThreshold) AND abs(BPS) > float(BPSThreshold)..

    I mean that either smaller then negative or higher then excessive, but it has to have a higher absolute BPS then the threshold..

    Code:
    for row in dealList:
            marginInSEK = float(row['DEAL_MARGIN'])*float(fxRatesDict[row['COUNTER_CCY']])
            BPS = float(row['DEAL_MARGIN']) / float(row['COUNTER_AMT']) * 100
            if marginInSEK < float(NegativeMarginThreshold) or marginInSEK > float(ExcessiveMarginThreshold) and abs(BPS) > float(BPSThreshold):
                marginSEKDict[row['DEAL_NO']] = [row['MARGIN_BRANCH_ID'], 
                                                 float(row['DEAL_MARGIN'])*float(fxRatesDict[row['COUNTER_CCY']])]
                dealDict[row['DEAL_NO']] = row
    values

    Code:
    row = dealDict[key]
    
    ExcessiveMarginThreshold = 50000 # is SEK
    NegativeMarginThreshold  = -100 # is SEK
    BPSThreshold = 0.3 # limit for BPS
    Am I using the right requirements?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    42
    Rep Power
    2
    Code:
    if abs(BPS) > float(BPSThreshold) and (marginInSEK < float(NegativeMarginThreshold) or marginInSEK > float(ExcessiveMarginThreshold)):
    SOLVED
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,905
    Rep Power
    481
    I don't rely on remembering the precedence rules for comparisons and the Boolean logical operators. I do parenthesize expressions involving operators beyond the scope of grade school algebraic precedence. (Back when I attended grade school. We're talking additions, multiplications, and powers.)

    Executable Iverson notation, APL and in it's final dialect named j processes noun verb sequences from right to left. There are no other rules to remember about that.
    [code]Code tags[/code] are essential for python code and Makefiles!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    510
    Rep Power
    33
    Originally Posted by b49P23TIvg
    I don't rely on remembering the precedence rules for comparisons and the Boolean logical operators. I do parenthesize expressions
    +1 Makes live simpler.

IMN logo majestic logo threadwatch logo seochat tools logo