几个小时前我写了这个程序:
while True:
print 'What would you like me to double?'
line = raw_input('> ')
if line == 'done':
break
else:
float(line) #doesn't seem to work. Why?
result = line*2
print type(line) #prints as string?
print type(result) #prints as string?
print " Entered value times two is ", result
print 'Done! Enter to close'
据我所知,它应该可以正常工作。问题是当我输入一个值(例如 6)时,我收到的是 66 而不是 12。这部分代码似乎是:
float(line)
不起作用,并且将 line 视为字符串而不是浮点数。我只做了一天python,所以它可能是一个菜鸟错误。谢谢你的帮助!