مسیرها
/
Python
Python
/
تمرین‌ها
/
دوازده روز
دوازده روز

دوازده روز

آسان

دستورالعمل‌ها

وظیفه‌ی شما در این تمرین این است که کدی بنویسید که متن ترانه‌ی «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.

توسعه‌ی تست‌محور

حتماً کامنت‌های بالای فایل تست‌ها را ببینید. این کامنت‌ها در درک خروجی موردانتظار تابع‌تان به شما کمک می‌کنند.

این چالش می‌تواند با کمترین کد و حجم زیادی متن سخت‌کدنویسی‌شده که بین بندها تکرار می‌شود حل شود. اما این آهنگ نوعی آهنگ تجمعی است که در آن هر بند تازه روی بند پیش از خودش بنا می‌شود. اگر چالش برنامه‌نویسی بیشتری می‌خواهید، به این فکر کنید که هر بند را از اجزایش بسازید. برای نمونه، در هر بند روز تغییر می‌کند و هدیه هم تغییر می‌کند و بقیه‌ی بند تقریباً یکسان است. چه راهبرد خوبی برای پرهیز از تکرار به نظرتان می‌رسد؟


منبع

Wikipediaاین لینک در پنجره یا تب جدیدی باز می‌شود.
ویرایش از طریق GitHub این لینک در پنجره یا زبانه‌ی جدیدی باز می‌شود
Python Exercism

آماده‌اید دوازده روز را شروع کنید؟

در Exercism ثبت‌نام کنید تا Python را همراه با 17 مفهوم146 تمرین و مربی‌گری انسانی واقعی یاد بگیرید و در آن استاد شوید، همه‌ی این‌ها رایگان.