Discuss / Python / 一直报错怎么办

一直报错怎么办

Topic source

胡朵kura

#1 Created at ... [Delete] [Delete and Lock User]

>>> def findMinAndMax(L):

...     if len(L) == 0:#判断元素个数是否为零

...         return (None,None)#如果为零则返回空

...     else:

...         max = L[0]

...         min = L[0]

...         for x in L:

...             if x < min:

...                 min = x

...             elif x > max:

...                 max = x

...         return (min,max)

...

>>> findMinAndMax(1,2,3)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

TypeError: findMinAndMax() takes 1 positional argument but 3 were given

>>>

这是一种错误

>>> findMinAndMax()

(None, None)

什么都不填没报错

>>> findMinAndMax(1)

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

  File "C:\Users\dell-ds\new.py", line 2, in findMinAndMax

    if len(L) == 0:#判断元素个数是否为零

TypeError: object of type 'int' has no len()

填一个数字报错

singcao

#2 Created at ... [Delete] [Delete and Lock User]

调用的时候这样填看看

findMinAndMax([1])

max 跟min是 系统里已经有的,不能在重新定义的

type 类型错误,你填的是多个 int 参数,肯定会报错的


  • 1

Reply