函数源码

_times = 0
def hannuota(nlist,mfrom,mpass,mto):global _timesn=len(nlist)#n=nlist._length_if n==1:_times+=1print('%-2d'%_times,nlist[0],':',mfrom,'------>',mto)else:hannuota(nlist[:n-1],mfrom,mto,mpass)hannuota(nlist[-1],mfrom,mpass,mto)hannuota(nlist[:n-1],mpass,mfrom,mto)if __name__=='__main__':print('the process is as following:\n')print('step   num:from------>to')hannuota([0,1,2],'A','B','C')
~

运行时报错:

the process is as following:step   num:from------>to
('1 ', 0, ':', 'A', '------>', 'C')
Traceback (most recent call last):File "hannuota.py", line 18, in <module>hannuota([0,1,2],'A','B','C')File "hannuota.py", line 10, in hannuotahannuota(nlist[:n-1],mfrom,mto,mpass)File "hannuota.py", line 11, in hannuotahannuota(nlist[-1],mfrom,mpass,mto)File "hannuota.py", line 4, in hannuotan=len(nlist)
TypeError: object of type 'int' has no len()

问题出在“hannuota(nlist[-1],mfrom,mpass,mto)”,nlist[-1]是一个int类型。log中已经指明出错行数了。

改正后的代码为:

_times = 0
def hannuota(nlist,mfrom,mpass,mto):global _timesn=len(nlist)#n=nlist._length_if n==1:_times+=1print('%-2d'%_times,nlist[0],':',mfrom,'------>',mto)else:hannuota(nlist[:n-1],mfrom,mto,mpass)hannuota([nlist[-1]],mfrom,mpass,mto)hannuota(nlist[:n-1],mpass,mfrom,mto)if __name__=='__main__':print('the process is as following:\n')print('step   num:from------>to')hannuota([0,1,2],'A','B','C')
~

运行结果:

the process is as following:step   num:from------>to
('1 ', 0, ':', 'A', '------>', 'C')
('2 ', 1, ':', 'A', '------>', 'B')
('3 ', 0, ':', 'C', '------>', 'B')
('4 ', 2, ':', 'A', '------>', 'C')
('5 ', 0, ':', 'B', '------>', 'A')
('6 ', 1, ':', 'B', '------>', 'C')
('7 ', 0, ':', 'A', '------>', 'C')

python 函数报错TypeError: object of type 'int' has no len()相关推荐

  1. 成功解决Python中出现的TypeError: object of type 'zip' has no len()

    成功解决Python中出现的TypeError: object of type 'zip' has no len() 不罗嗦,直接解决问题! 目录 解决问题 解决思路 解决方法 解决问题 TypeEr ...

  2. 成功解决TypeError: object of type ‘int‘ has no len()

    成功解决TypeError: object of type 'int' has no len() 目录 解决问题 解决思路 解决方法 解决问题 TypeError: object of type 'i ...

  3. Python 3 报错 TypeError: object() takes no parameters【新手必过坑之一】

    在学习 Python 3 类的时候,有如下程序: class Dog():def __init__(self,name,age):#初始化属性name和ageself.name = nameself. ...

  4. python2.7web代码用python3.6运行时,浏览器发送请求报错TypeError: Object of type 'bytes' is not JSON serializable的解决办法

    浏览器的Cookie由Python 2代码设置.Python 3将cookie内容解释为字节字符串.只要清除浏览器cookie就好了.

  5. python3中调用map函数报错map object at 0x000001EF004D97B8

    python3中调用map函数报错<map object at 0x000001EF004D97B8> 在python中这样的一段代码报错: a=map(int,input().split ...

  6. DataFrame/Series运行round()函数报错“TypeError: a float is required”解决办法

    DataFrame/Series运行round()函数报错"TypeError: a float is required"解决办法 原代码片段: #把数据按年龄分层,然后按照不同层 ...

  7. TypeError: object of type 'zip' has no len()、'zip' object is not subscriptable

    TypeError: object of type 'zip' has no len().'zip' object is not subscriptable zip 对象没有length属性不可以遍历 ...

  8. pandas统计文章字数:TypeError: object of type ‘float‘ has no len()

    使用pandas.read_csv()读取文件, 统计文章字数时:train['text_len'] = train['text'].map(len) 报错: TypeError: object of ...

  9. python报错TypeError: unsupported operand type(s) for -: ‘decimal.Decimal‘ and ‘float‘的解决方法

    问题描述 在编写python代码时,进行小数位相减时出现 TypeError: unsupported operand type(s) for -: 'decimal.Decimal' and 'fl ...

最新文章

  1. php 操作分表代码
  2. Linux下批量重命名文件名为数字索引编号(0~N.xxx)的方法
  3. Linux虚拟机基本操作
  4. mysql 中文 length_mysql length()中文长度一些问题整理
  5. 如何测量接收机到卫星的距离
  6. Hello World With JBoss Modules
  7. 在神经网络中使用辍学:不是一个神奇的子弹
  8. jax-rs jax-ws_极端懒惰:使用Spring Boot开发JAX-RS服务
  9. HBase使用场景和成功案例 (转)
  10. 扔盘子(51Nod-1279)
  11. oracle 的基本命令(一)
  12. LoggingFilter Session 以及Async
  13. 干货:react新手入门之react小书
  14. 基于redis实现活跃用户统计功能
  15. python的文件怎么删除干净_python 实现彻底删除文件夹和文件夹下的文件
  16. 错误:Error: Could not open client transport with JDBC Uri: jdbc:hive2://ducking:10000: java.net.Connec
  17. s饥荒服务器物品id,饥荒物品代码大全
  18. MATLAB导入数据importdata功能
  19. python贪吃蛇控制台_通过 PRA 的 python-pygame 玩转贪吃蛇
  20. oracle账户余额表和明细表,科目余额表与明细账

热门文章

  1. sa387gr11cl2是什么材料,sa387gr11cl2美标钢板性能介绍
  2. idea 2018版的无法在线下载安装插件解决方法
  3. 大数据技术之_20_Elasticsearch学习_01_概述 + 快速入门 + Java API 操作 + 创建、删除索引 + 新建、搜索、更新删除文档 + 条件查询 + 映射操作
  4. CocoStudio UI 编辑器的使用
  5. 治安防控平台搭建,为您打造平安社区
  6. Switch中的参数
  7. RTT and RTO
  8. [DAY003]考研数学极限的计算知识点与题目总结(三)
  9. 数据仓库主题设计及元数据设计
  10. JAVA实现删除文件夹和文件