类型错误:不支持 + 的操作数类型:'NoneType' 和 'str'/基本转换

郑敏镐

这是我的代码,我只是不明白这个代码不起作用。

def theBase(n, b):
   convertString = "0123456789"
   if n < b:
      return convertString[n]
   else:
      return toBase(n//b,b) + convertString[n%b]

def toBase(n, b):
   print(theBase(n, b), end="")

def main():
    n = int(input())
    b = int(input())
    print(n, "in base", b, "is ", end="")
    toBase(n, b)
if __name__ == "__main__":
    main()

不要修改main函数

霍克

出现问题的原因是函数toBase()返回,None因为没有明确的 return 语句。然后函数中的最后一行theBase()尝试将返回值toBase()(即 None)添加到一个字符串中,这会给您提供您看到的异常。

我认为您有一个简单的错误,theBase()应该在哪里调用自己,而不是toBase()(请参阅该函数的最后一行)。以下将解决问题:

def theBase(n, b):
   convertString = "0123456789"
   if n < b:
      return convertString[n]
   else:
      return theBase(n//b,b) + convertString[n%b]

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

+不支持的操作数类型:'NoneType'和'str'和'int'

来自分类Dev

Python TypeError:+不支持的操作数类型:'NoneType'和'str'

来自分类Dev

- 不支持的操作数类型:“str”和“str”

来自分类Dev

+ =不支持的操作数类型:“ NoneType”和“ list”

来自分类Dev

+不支持的操作数类型:“ NoneType”和“ int”

来自分类Dev

+不支持的操作数类型:“ int”和“ str”

来自分类Dev

+不支持的操作数类型:“ WindowsPath”和“ str”

来自分类Dev

+不支持的操作数类型(“ str”和“ int”)

来自分类Dev

类型错误:* 不支持的操作数类型:'int' 和 'NoneType'

来自分类Dev

类型错误:不支持 / 的操作数类型:'NoneType' 和 'float'

来自分类Dev

类型错误:不支持 str 和 int 的操作数类型

来自分类Dev

Python错误:+不支持的操作数类型:“ int”和“ NoneType”

来自分类Dev

Python错误:+不支持的操作数类型:“ int”和“ NoneType”

来自分类Dev

+不支持的操作数类型:“ float”和“ str”错误

来自分类Dev

python错误; +不支持的操作数类型:“ int”和“ str”

来自分类Dev

获取+的错误不支持的操作数类型:“ int”和“ str”

来自分类Dev

类型错误:不支持 / 的操作数类型:'NoneType' 和 'int',对于extract_image_patches

来自分类Dev

如何修复 [类型错误:+= 不支持的操作数类型:'builtin_function_or_method' 和 'str'] Python 中的错误

来自分类Dev

TypeError:/不支持的操作数类型:'str'和'str'django setting.py

来自分类Dev

Pandas Groupby : TypeError: 不支持的操作数类型 -: 'str' 和 'str'

来自分类Dev

TypeError: 不支持 & 的操作数类型:'str' 和 'str' 如何解决

来自分类Dev

TypeError:+不支持的操作数类型:“ int”和“ NoneType”

来自分类Dev

TypeError:%不支持的操作数类型:“ NoneType”和“ int”

来自分类Dev

Python:TypeError:+不支持的操作数类型:“ NoneType”和“ int”

来自分类Dev

TensorFlow 1.x:TypeError:/:不支持的操作数类型:'NoneType'和'int'

来自分类Dev

TypeError:+ =不支持的操作数类型:“ datetime.timedelta”和“ NoneType”

来自分类Dev

TypeError:+不支持的操作数类型:“ NoneType”和“ list”

来自分类Dev

TypeError:%不支持的操作数类型:“ NoneType”和“ int”

来自分类Dev

TypeError:+不支持的操作数类型:“ NoneType”和“ int”

Related 相关文章

  1. 1

    +不支持的操作数类型:'NoneType'和'str'和'int'

  2. 2

    Python TypeError:+不支持的操作数类型:'NoneType'和'str'

  3. 3

    - 不支持的操作数类型:“str”和“str”

  4. 4

    + =不支持的操作数类型:“ NoneType”和“ list”

  5. 5

    +不支持的操作数类型:“ NoneType”和“ int”

  6. 6

    +不支持的操作数类型:“ int”和“ str”

  7. 7

    +不支持的操作数类型:“ WindowsPath”和“ str”

  8. 8

    +不支持的操作数类型(“ str”和“ int”)

  9. 9

    类型错误:* 不支持的操作数类型:'int' 和 'NoneType'

  10. 10

    类型错误:不支持 / 的操作数类型:'NoneType' 和 'float'

  11. 11

    类型错误:不支持 str 和 int 的操作数类型

  12. 12

    Python错误:+不支持的操作数类型:“ int”和“ NoneType”

  13. 13

    Python错误:+不支持的操作数类型:“ int”和“ NoneType”

  14. 14

    +不支持的操作数类型:“ float”和“ str”错误

  15. 15

    python错误; +不支持的操作数类型:“ int”和“ str”

  16. 16

    获取+的错误不支持的操作数类型:“ int”和“ str”

  17. 17

    类型错误:不支持 / 的操作数类型:'NoneType' 和 'int',对于extract_image_patches

  18. 18

    如何修复 [类型错误:+= 不支持的操作数类型:'builtin_function_or_method' 和 'str'] Python 中的错误

  19. 19

    TypeError:/不支持的操作数类型:'str'和'str'django setting.py

  20. 20

    Pandas Groupby : TypeError: 不支持的操作数类型 -: 'str' 和 'str'

  21. 21

    TypeError: 不支持 & 的操作数类型:'str' 和 'str' 如何解决

  22. 22

    TypeError:+不支持的操作数类型:“ int”和“ NoneType”

  23. 23

    TypeError:%不支持的操作数类型:“ NoneType”和“ int”

  24. 24

    Python:TypeError:+不支持的操作数类型:“ NoneType”和“ int”

  25. 25

    TensorFlow 1.x:TypeError:/:不支持的操作数类型:'NoneType'和'int'

  26. 26

    TypeError:+ =不支持的操作数类型:“ datetime.timedelta”和“ NoneType”

  27. 27

    TypeError:+不支持的操作数类型:“ NoneType”和“ list”

  28. 28

    TypeError:%不支持的操作数类型:“ NoneType”和“ int”

  29. 29

    TypeError:+不支持的操作数类型:“ NoneType”和“ int”

热门标签

归档