为什么我会不断收到这两个错误?

时间:2018-09-03 17:07:36

标签: python int

我正在codewars.com上进行一次7 kyu编码挑战,而这样做的时候我得到了以下消息:

Traceback (most recent call last):

  File "new.py", line 10, in <module>
    series_sum(5)
  File "new.py", line 3, in series_sum
    if "." in n:
TypeError: argument of type 'int' is not iterable

此代码:

def series_sum(n):
    str(n)
    if "." in n:
        n=n[:index('.')]+'00'
    elif '.' not in n:
        n = n+'.00'
series_sum(5)

有人可以解释为什么吗?

1 个答案:

答案 0 :(得分:0)

您应该这样修改它:

def series_sum(n):
    n = str(n)
    if "." in n:
        n=n[:index('.')]+'00'
    elif '.' not in n:
        n = n+'.00'
series_sum(5)