例入力:[5,9、2、4、1、3]機能ではなく、同じ項目を持つ単一のリストのリストとして各項目を返して
期待出力:[9,2 、1]
関数は、以下の項目と同じ項目を持つ単一のリストではなく、リストとして各項目を返します。
[9]
を[2]
[1]
def divide_digits(a):
"""
This is where the function's Document string (docstring) goes.
"""
# make a shallow copy of the int_list and assign it to variable lst_copy
lst_copy = a[:]
# sort lst.copy
lst_copy.sort()
# as long as the lst_copy is not empty:
while lst_copy:
# get/pop the element from the beginning and at the end of the new_list
largest_num = lst_copy.pop()
smallest_num = lst_copy.pop(0)
new_list = []
# perform the division of two these elements
result = largest_num/smallest_num
# round down the result to the nearest integer
# append the result of the division operation to the new list
new_list.append(round(result))
# return the new_list
return new_list
あなた 'return'は内側にありますループ?? –
あなたのインデントが奇妙に見えます。なぜあなたはwhileループの中に戻りますか?そして、while_loopの外側でnew_listを定義して、すべての要素を含めるべきではありませんか? – Secespitus