python-3.x - 带有打印功能的 Python 3 中的 TypeError
问题描述
所以我一直在关注这段代码并将其放入,一切似乎都进展顺利,直到我打印最终字符串的最后一行出现 TypeError。我的错误在哪里?
kingName = input("Yo King! Please type in your name at the prompt")
numJewels = input("Hey " + kingName + ", how many jewels are there?")
numJewels = int(numJewels)
costOfEachJewel = input("Yo " + kingName + ", how much does each jewel cost?")
costOfEachJewel = int(costOfEachJewel)
print (costOfEachJewel * numJewels)
dudeNames = ["Athos", "Pothos", "Aramis"]
dudeAges = [55,34, 67]
dudeNames.insert(0, "D'Artagnan")
print (dudeNames)
dudeAges.append(16)
print (dudeAges)
tempVariable = dudeNames.pop(0)
tempVariable
dudeNames.append(tempVariable)
print (dudeNames)
print (dudeAges)
print ("Total number of dudes: " + str(len(dudeNames)))
dudeToKill = input("Yo " + kingName + "please enter the # of the dude to kill")
print ("zapping all history of " + str(len(dudeNames[dudeToKill-1])))
解决方案
dudeToKill
必须是一个,在执行操作之前int
转换为input
。int
dudeToKill - 1
dudeToKill = int(input("Yo " + kingName + "please enter the # of the dude to kill"))
推荐阅读
- sql - 将逗号分隔的列数据拆分为具有 50 多个字段的附加列
- jquery - 如何在按下的按钮上动态设置类?
- java - 如何调用 CallBack(); 执行成功后再次运行?
- html - xslfo, xsl, pdf, html: 在某些页面之后为动态生成的 pdf 文档重置页脚页码
- java - MP4 视频的文件输入/输出流
- django - 在 django-rest-framework 中发送电子邮件的最佳位置在哪里?
- php - 尝试使用 isset 设置值但仍然出现错误
- python - 合并并创建一个包含相同 id 的所有记录的新 JSON 数组
- ms-access - 在 MS Access 2016 中向现有查询(不是表)添加自动增量
- java - stringbuffer 在连接中比 string 快我可以知道它们是如何实现的吗