# gym.py # Lillian Lee (LJL2@cornell.edu) # Jan 31, 2013 """Demonstrate defining functions in a module. Functions for processing gymnastics results. """ def dscore(info): """Returns: difficulty score, as a float, represented in info. Precondition: info is a string with commas separating its component values: last name, difficulty score, execution score, penalty.""" 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 # bad style to put these here, but the code below is meant to be inpenetrable import string import re def dscore_alt(info): """Returns: difficulty score, as a float, represented in info. This is a poorly documented, and possibly buggy, re-implementation; it exists merely to demonstrate some testing concepts. Precondition: info is a string with commas separating its component values: last name, difficulty score, execution score, penalty.""" #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