大佬幫看看,為啥錯了
def?square_of_sum(L): ????sum?=?0 ????while?True: ????????if?x?not?in?L: ????????????break ????????else: ????????????sum?=?sum?+?x?*?x print(square_of_sum([1,2,3,4,5]))
def?square_of_sum(L): ????sum?=?0 ????while?True: ????????if?x?not?in?L: ????????????break ????????else: ????????????sum?=?sum?+?x?*?x print(square_of_sum([1,2,3,4,5]))
2018-09-27
舉報
2018-09-27
X無定義,for循環中會直接把列表的值賦予x,而if不會
2018-09-27
def square_of_sum(L):
? ? sum = 0
? ? for x in L:
? ? ? ? sum = sum + x * x
? ? return sum
print(square_of_sum([1,2,3,4,5]))
2018-09-27
x 無中生有