【发布时间】:2020-04-19 20:47:30
【问题描述】:
所以我一直在关注这段代码并将其放入,一切似乎都很顺利,直到我打印最终字符串的最后一行出现 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是一个字符串,你希望dudeToKill - 1做什么?
标签: python-3.x string typeerror