# gym.py
# Lillian Lee (LJL2), Steve Marschner (SRM2)
# Feb 4, 2014


"""Demonstrate defining functions in a module.

Functions for processing gymnastics results.
"""

# version that students should be able to come up with
def dscore_readable(info):
    """Returns: difficulty score, as a float, represented in info.

    Precondition: The input variable info holds a string with commas separating its
    component values: last name, difficulty score, execution score, penalty.
    All scores are legal. [There was some debate in lecture about what this
    means, exactly.]
    The last name contains at least one character."""

    startcomma = info.index(',')
    tail = info[startcomma+1:] # substring of info starting after 1st comma
    endcomma = tail.index(',')
    return float(tail[:endcomma]) # float() takes care of whitespace

# A poorly documented, and possibly incorrect, and likely incomprehensible
# implementation; we've written it merely to demonstrate function testing.
def dscore(info):
    """Returns: difficulty score, as a float, represented in info.

    Precondition: the input variable info is a string with commas separating its
    component values: last name, difficulty score, execution score, penalty.
    All scores are legal.
    [There was some debate in lecture about what this
    means, exactly.]    
    The last name contains at least one character."""

    # bad style to place here, but convenient for lecture purposes    
    import string
    import re

    #Implemented in a way unfamiliar/unreadable to the typical CS1110 student, on purpose.
    replacestring = '[' + string.punctuation.replace('.','').replace('-','') + '-' + ']'
    try:
        return float(re.split(replacestring,info)[1])
    except:
        return -15.0 # bogus score to make sure there is always a returned value