#Python: Twelve Days Exercise

8 messages · Page 1 of 1 (latest)

ashen flax
#

I'm currently on the twelve days exercise and I've passed 12/15 of the tests. However, I just cannot understand how it wants me to format the answer, the error messages it gives I'm struggling to understand, and the notes in the tests tab also aren't helping (for example, what is implicit line joining?)

I've attached my code and the errors it gives. Any help would be hugely appreciated. Thanks

untold lodge
#

Please share your code and errors using a codeblock. Those are easier to read. And copy paste. It's hard to load an image into a text editor.

tidal tuskBOT
ashen flax
#

Ah apologies, thank you.

def recite(start_verse, end_verse):
    days = ["second","third","fourth","fifth","sixth","seventh","eighth","ninth","tenth","eleventh","twelfth"]
    gifts = ["and a Partridge in a Pear Tree.","two Turtle Doves","three French Hens","four Calling Birds", "five Gold Rings","six Geese-a-Laying","seven Swans-a-Swimming","eight Maids-a-Milking","nine Ladies Dancing","ten Lords-a-Leaping","eleven Pipers Piping","twelve Drummers Drumming"]
    joined_gifts = []

    for i in range(1,len(gifts)+1):
        joined_gifts.append(gifts[:i])

    for item in joined_gifts:
        item.reverse()

    final_song = ["On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree."]

    for index,day in enumerate(days):
        final_song.append(f"On the {day} day of Christmas my true love gave to me: {', '.join(joined_gifts[index+1])}")
    return ["\n".join(final_song[start_verse-1:end_verse])]
untold lodge
#

Could you also share the test output as a codeblock?

ashen flax
#
AssertionError: Lists differ: ['On [74 chars]Tree.\nOn the second day of Christmas my true [188 chars]ee.'] != ['On [74 chars]Tree.', 'On the second day of Christmas my tru[192 chars]ee.']

First differing element 0:
'On t[73 chars]Tree.\nOn the second day of Christmas my true [187 chars]ree.'
'On t[73 chars]Tree.'

Second list contains 2 additional elements.
First extra element 1:
'On the second day of Christmas my true love gave to me: two Turtle Doves, and a Partridge in a Pear Tree.'

  ['On the first day of Christmas my true love gave to me: a Partridge in a Pear '
-  'Tree.\n'
?        --

+  'Tree.',
?         +

   'On the second day of Christmas my true love gave to me: two Turtle Doves, '
-  'and a Partridge in a Pear Tree.\n'
?                                  --

+  'and a Partridge in a Pear Tree.',
?                                   +

   'On the third day of Christmas my true love gave to me: three French Hens, '
   'two Turtle Doves, and a Partridge in a Pear Tree.']
untold lodge
#

It looks like you're returning a list containing a single string? The tests expect a list with one string per verse, ie end - start strings

ashen flax
#

Okay that makes sense, thank you. I'll try implementing that change now