Source

PythonDojo / BowlingWithAVengeance / bowling.py

STRIKE = 10
SPARE = '/'

def parse_roll(roll):
    if roll == '/':
        return SPARE
    return STRIKE
    
def frame_score(frame):
    return sum(frame)
    
def is_strike(frame):
    if frame[0]==10:
        return True
    return False

def get_score(frames):
    score = 0
    
    for index, frame in enumerate(frames):
        score += frame_score(frame)
        if index < len(frames) - 1:
            # if this is not the last frame, we might want to
            # look at future frames for additional scores
            next_frame = frames[index+1]
            if is_strike(frame):
                score += frame_score(next_frame)
                if is_strike(next_frame):
                    score = 25
    return score