Doctest failing

Tigerstyle laddosingh at
Sat Sep 10 13:20:17 CEST 2011

Hi guys.

I'm strugglin with some homework stuff and am hoping you can help me
out here.

This is the code:

small_words = ('into', 'the', 'a', 'of', 'at', 'in', 'for', 'on')

def book_title(title):
    """ Takes a string and returns a title-case string.
    All words EXCEPT for small words are made title case
    unless the string starts with a preposition, in which
    case the word is correctly capitalized.
    >>> book_title('DIVE Into python')
    'Dive into Python'
    >>> book_title('the great gatsby')
    'The Great Gatsby'
    >>> book_title('the WORKS OF AleXANDer dumas')
    'The Works of Alexander Dumas'
    new_title = []
    title_split = title.strip().lower().split()
    for word in title_split:
        if title_split[0] in small_words:
        elif word in small_words:
    return(' '.join(new_title))

def _test():
    import doctest, refactory
    return doctest.testmod(refactory)
if __name__ == "__main__":

All tests are failing even though I am getting the correct output on
the first two tests. And the last test still gives me "Of" instead of

Any help is appreciated.



More information about the Python-list mailing list