【发布时间】:2013-05-14 03:11:11
【问题描述】:
我几个小时前写了这个程序:
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,所以它可能是一个菜鸟错误。感谢您的帮助!
【问题讨论】: