Skip to content
Snippets Groups Projects
util.py 351 B
Newer Older
def initialise(dictionary, label, value):
    if label not in dictionary:
        dictionary[label] = value

def checkBound(f):
    if f >= 0 and f <= 1:
        return f
    else:
        print("Expected a ratio between 0 and 1 (inclusive)")
        exit(1)

def parseRatio(s):
    return checkBound(int(s[:-1]) / 100 if s[-1] == '%' else float(s))