이 연습 문제에서 해야 할 일은 "The Twelve Days of Christmas"라는 노래의 가사를 반환하는 코드를 작성하는 거예요.
"The Twelve Days of Christmas"는 널리 알려진 영어 크리스마스 캐럴이에요. 노래의 각 절은 그 앞 절에 이어서 내용이 쌓여 가요.
코드가 반환하는 가사는 아래에 나온 전체 노랫말과 정확히 일치해야 해요.
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.
테스트 파일 맨 위에 있는 주석을 꼭 확인해 봐요. 함수가 어떤 출력을 내야 하는지 이해하는 데 도움이 될 거예요.
이 연습 문제는 최소한의 코드와, 각 절 사이에 중복되는 많은 하드코딩된 텍스트만으로도 풀 수는 있어요. 그런데 이 노래는 누적 노래의 한 종류로, 새 절이 나올 때마다 앞의 절을 이어받아 만들어져요. 프로그래밍 연습을 좀 더 해 보고 싶다면, 각 절을 부분부분 모아서 조립해 보는 건 어때요? 예를 들어 각 절에서 요일이 바뀌고 선물이 바뀌며, 나머지 부분은 거의 똑같아요. 그럼 반복을 피하려면 어떤 방법이 좋을까요?
Exercism에 가입하고 Python 트랙을 개념 17개연습 문제 146개, 그리고 실제 사람의 멘토링과 함께 배우고 익혀 보세요. 모두 무료예요.