我有以下代码:
if (sum(L) % 3) == 0:
biggest_list = []
for i in range(len(L)):
biggest_list.append(max(L))
L.remove(max(L))
string_l = []
for i in range(len(biggest_list)):
string_l.append(str(biggest_list[i]))
big_word = ''.join(string_l)
big_number = int(big_word)
v = type(big_number)
print "big_number (should be number)"
print t
return big_number
为什么big_number
变量未转换为整数?以及如何将其转换为整数?
当我运行这段代码时,我的Python 2.7.12 Shell告诉我<type 'str'>
应该<type 'int'>
代替。
这是整个功能:
def answer(L):
if (sum(L) % 3) == 0:
biggest_list = []
for i in range(len(L)):
biggest_list.append(max(L))
L.remove(max(L))
string_l = []
for i in range(len(biggest_list)):
string_l.append(str(biggest_list[i]))
big_word = ''.join(string_l)
big_number = int(big_word)
return big_number
该函数将整数列表作为输入,检查它是否可以被3除,并返回可以由这些整数组成的最大数。