我正在上一堂关于我目前卡住的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'个正方形数字。这就是为什么你很难理解它的原因。 –