定義function,印出歌詞

選了之前喜歡的shallow來練習定義function

Lady Gaga, Bradley Cooper — Shallow (A Star Is Born)

歌詞:

Tell me somethin’, girl
Are you happy in this modern world?
Or do you need more?
Is there somethin’ else you’re searchin’ for?

I’m falling
In all the good times I find myself
Longin’ for change
And in the bad times I fear myself

Tell me something, boy
Aren’t you tired tryin’ to fill that void?
Or do you need more?
Ain’t it hard keeping it so hardcore?

I’m falling
In all the good times I find myself
Longing for change
And in the bad times I fear myself

I’m off the deep end, watch as I dive in
I’ll never meet the ground
Crash through the surface, where they can’t hurt us
We’re far from the shallow now

In the shallow, shallow
In the shallow, shallow
In the shallow, shallow
We’re far from the shallow now

Oh, oh, oh, oh
Whoah!

I’m off the deep end, watch as I dive in
I’ll never meet the ground
Crash through the surface, where they can’t hurt us
We’re far from the shallow now

In the shallow, shallow
In the shallow, shallow
In the shallow, shallow
We’re far from the shallow now

用function印出歌詞:

func tellmegirl() {print("Tell me somethin', girl")print("Are you happy in this modern world?")print("Or do you need more?")print("Is there somethin' else you're searchin' for?")}func imfalling(version:String) {print("I'm falling")print("In all the good times I find myself")print(version + " for change")print("And in the bad times I fear myself")}func tellmeboy() {print("Tell me something, boy")print("Aren't you tired tryin' to fill that void?")print("Or do you need more?")print("Ain't it hard keeping it so hardcore?")}func deepend() {print("I'm off the deep end, watch as I dive in")print("I'll never meet the ground")print("Crash through the surface, where they can't hurt us")print("We're far from the shallow now")}func shallow() {print("In the shallow, shallow")}func intheshallow() {shallow()shallow()shallow()print("We're far from the shallow now")}func oh() {print("Oh, oh, oh, oh")print("Whoah!")}tellmegirl()imfalling(version:"Longin'")tellmeboy()imfalling(version:"Longing")deepend()intheshallow()oh()deepend()intheshallow()

練習在function中放入另一個function:

func shallow() {print("In the shallow, shallow")}func intheshallow() {shallow()shallow()shallow()print("We're far from the shallow now")}

I’m falling那邊的歌詞第一次是Longin’ for change,第二次是Longing for change,寫法上不同所以用來練習修改歌詞

func imfalling(version:String) {print("I'm falling")print("In all the good times I find myself")print(version + " for change")print("And in the bad times I fear myself")}tellmegirl()imfalling(version:"Longin'")tellmeboy()imfalling(version:"Longing")

出來的結果就會跟原來的歌詞一樣

Tell me somethin', girlAre you happy in this modern world?Or do you need more?Is there somethin' else you're searchin' for?I'm fallingIn all the good times I find myselfLongin' for changeAnd in the bad times I fear myselfTell me something, boyAren't you tired tryin' to fill that void?Or do you need more?Ain't it hard keeping it so hardcore?I'm fallingIn all the good times I find myselfLonging for changeAnd in the bad times I fear myself

--

--