我正在上一堂關於我目前卡住的codecademy的課程,不知道如何繼續 - 這是關於返回值的。返回值問題
所述指令:
編寫取整數作爲參數的方法,並返回整數乘以十。在定義它並打印出其返回值後,在代碼中調用times_ten。
什麼在腳本中給出的是:
def times_ten(integer)
# your code here
end
# call times_ten here
這是它給人的例子,但我有一個很難理解:
def first_squares(number_of_squares)
squares = []
idx = 0
while idx < number_of_squares
squares.push(idx * idx)
idx = idx + 1
end
return squares
end
puts("How many square numbers do you want?")
number_of_squares = gets.to_i
squares = first_squares(number_of_squares)
idx = 0
while idx < squares.length
puts(squares[idx])
idx = idx + 1
end
感謝您的幫助
你有了解return語句是什麼問題還是呢? – MarsAtomic
...所以你想要一個教程來幫助你的教程。有趣。我以前從來沒有見過。 –
看來,您的示例腳本與您的問題無關。你的示例腳本所做的是打印'n'個正方形數字。這就是爲什麼你很難理解它的原因。 –