mardi 1 janvier 2019

How to filter variables through multiple conditionals

I'm writing code that will assign rank to Brazilian Jiu Jitsu Players. The ranking formula is borrowed from chess (ELO Rating method) but it needs some adjustments to properly reflect BJJ. I have three conditional functions which the score must pass through so that it is updated properly:

`Elo_Score is already calculated based on original formula and now the score must pass through ONE of the following functions to see if it needs adjustment.

def Weight_Age_Rank_Dif():
    """this functions checks for a certain weight, age AND rank difference 
    between two players. 
    (it will kick in if the difference is bigger than 10 kilos, 15 years, 
    AND 100 rating points; so think of it as a smaller, less experienced 
    older guy fighting a bigger, more experienced and much younger 
    opponent)."""

def Weight_Dif():
    """this function checks for a weight difference only (10 or more kilos 
    between opponents)"""

def Age_Dif():
    """this function checks for an age difference only (10 or more years between 
    two players AND at least one player over 50; so it would have no effect 
    between two guys who were 22 and 34)."""

# PRINT RESULTS

The idea behind these functions is to provide a cushion to the underdogs (smaller, less experienced or significantly older guys). If they win, they win more points and if they lose they lose less.

My question is how do we make sure that only ONE of the functions is executed? So if two players met all conditions for the first function than how do we make sure the code skips directly to the # PRINT RESULTS without touching the other two?

Also, each function has multiple conditional statements. For example in the Weight_Age_Rank_Dif() function there are 8 conditional statements. When one of these conditionals is met how can we make the code exit the function, skip the other two functions and go directly to # PRINT RESULTS?

I have tried to make the entire script into one giant conditional statement with a bunch of elif statements but it doesn't work because nested conditionals within elif statements throw an UnboundLocalError and it seems inefficient to put in a global variable each time.

Aucun commentaire:

Enregistrer un commentaire