【发布时间】:2013-02-15 16:45:52
【问题描述】:
无法计算距离? (TypeError: unsupported operand type(s) for /: 'int' and 'str') 建议让 python 识别哪个名称与哪个数字对应?这样我就可以让它打印正确的名字和获胜时间? (字符串?)
def main():
print "~*~*~*~*~*~ Timbuktu Archery Contest ~*~*~*~*~*~"
archerList = [] #list
timeList = [] #list2
distanceList = [] #list3
name = raw_input ("Enter contestants first name: ")
s = str(name)
archerList.append(name)
while name:
time = raw_input ("Enter time (in milliseconds) for %s: " % s)
timeList.append(time)
name = raw_input ("Enter contestants first name: ")
s = str(name)
archerList.append(name)
else:
print "Slowest archer was " , min(timeList)
print "Fastest archer was " , max(timeList)
for time in timeList:
distance = ((230/time)*681.1)
distanceList.append(distance)
【问题讨论】:
-
从
raw_input得到的一切都是一个字符串。您必须在代码中将其转换为适当的类型。 -
运行代码后,您的 while 循环中似乎存在无限循环。它可能是我正在使用的平台(code.hs)。
标签: python