在数组中求大和的代码:
code for finding the large sum in the array:
def maxsum(arry):
if len(arry)==0:
return 0
summ,maximum_sum=0
for i in arry:
summ=summ+i
maximum_sum=max(summ,maximum_sum)
return maximum_sum
maxsum([1,2,-1,-2])
得到以下错误:TypeError
Traceback (most recent call last)
<ipython-input-5-59dc92538282> in <module>
7 maximum_sum=max(summ,maximum_sum)
8 return maximum_sum
----> 9 maxsum([1,2,-1,-2])
10
<ipython-input-5-59dc92538282> in maxsum(arry)
2 if len(arry)==0:
3 return 0
----> 4 summ,maximum_sum=0
5 for i in arry:
6 summ=summ+i
TypeError: cannot unpack non-iterable int object
变量赋值错误.
def maxsum(arry):
if len(arry)==0:
return 0
summ,maximum_sum=0,0 # Changes
for i in arry:
summ=summ+i
maximum_sum=max(summ,maximum_sum)
return maximum_sum
https://note.nkmk.me/en/python-多变量值/
无法解压不可迭代的 int 对象:
cannot unpack non-iterable int object :
---------这是因为它试图将其转换为元组.
---------This is because it tried to convert it to tuple.
这篇关于Python:TypeError:无法解压不可迭代的 int 对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
如何在python中的感兴趣区域周围绘制一个矩形How to draw a rectangle around a region of interest in python(如何在python中的感兴趣区域周围绘制一个矩形)
如何使用 OpenCV 检测和跟踪人员?How can I detect and track people using OpenCV?(如何使用 OpenCV 检测和跟踪人员?)
如何在图像的多个矩形边界框中应用阈值?How to apply threshold within multiple rectangular bounding boxes in an image?(如何在图像的多个矩形边界框中应用阈值?)
如何下载 Coco Dataset 的特定部分?How can I download a specific part of Coco Dataset?(如何下载 Coco Dataset 的特定部分?)
根据文本方向检测图像方向角度Detect image orientation angle based on text direction(根据文本方向检测图像方向角度)
使用 Opencv 检测图像中矩形的中心和角度Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 检测图像中矩形的中心和角度)