Doze Dias

Doze Dias

Fácil

Instruções

Neste exercício, a tua tarefa é escrever código que devolva a letra da canção: "The Twelve Days of Christmas".

"The Twelve Days of Christmas" é uma conhecida canção de Natal inglesa. Cada estrofe seguinte da canção baseia-se na anterior.

A letra que o teu código devolve deve corresponder exatamente ao texto completo da canção apresentado abaixo.

Letra

On the first day of Christmas my true love gave to me: a Partridge in a Pear Tree.

On the second day of Christmas my true love gave to me: two Turtle Doves, 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.

On the fourth day of Christmas my true love gave to me: four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the fifth day of Christmas my true love gave to me: five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the sixth day of Christmas my true love gave to me: six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the seventh day of Christmas my true love gave to me: seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the eighth day of Christmas my true love gave to me: eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the ninth day of Christmas my true love gave to me: nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the tenth day of Christmas my true love gave to me: ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the eleventh day of Christmas my true love gave to me: eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

On the twelfth day of Christmas my true love gave to me: twelve Drummers Drumming, eleven Pipers Piping, ten Lords-a-Leaping, nine Ladies Dancing, eight Maids-a-Milking, seven Swans-a-Swimming, six Geese-a-Laying, five Gold Rings, four Calling Birds, three French Hens, two Turtle Doves, and a Partridge in a Pear Tree.

Desenvolvimento orientado a testes

Não deixes de ver os comentários no topo do ficheiro de testes. Ajudam-te a compreender o resultado esperado da tua função.

Este desafio podia ser resolvido com um mínimo de código e muito texto escrito diretamente no código, duplicado entre as estrofes. No entanto, esta canção é um tipo de canção cumulativa, em que cada nova estrofe se constrói sobre a que vem antes. Se quiseres um desafio de programação maior, considera montar cada estrofe a partir das suas partes. Por exemplo, em cada estrofe, o dia muda e o presente muda, e o resto da estrofe é praticamente igual. Qual poderá ser uma boa estratégia para evitar a repetição?


Fonte

WikipediaO link abre numa nova janela ou separador
Editar via GitHub A ligação abre numa nova janela ou separador
Python Exercism

Estás pronto para começar Doze Dias?

Inscreve-te no Exercism para aprenderes e dominares Python com 17 conceitos146 exercícios, e mentoria humana real, tudo grátis.