俗話說,少了一根馬蹄釘,就失去了一個王國。
給定一個輸入陣列,產生對應的諺語。
例如,給定["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]這個陣列,你要輸出這首諺語的完整內容:
For want of a nail the shoe was lost.
For want of a shoe the horse was lost.
For want of a horse the rider was lost.
For want of a rider the message was lost.
For want of a message the battle was lost.
For want of a battle the kingdom was lost.
And all for the want of a nail.
注意,輸入的陣列可能不同;你的解法應該要能處理任意長度與內容的陣列。 輸出的文字中,不該有任何一行是固定不變的字串;每一行都應該隨著給定的輸入而變化。
在unpacking-and-multiple-assignment中,你學到了處理任意長度的lists/tuples,以及任意長度的函式引數的多種技巧。
這個練習很適合拿來練習這些技巧。
這個 track 的測試案例多了一個名為qualifier的關鍵字引數。
你應該用這個關鍵字引數的值,來修改你的諺語的最後一段。