例如,当我输入2 * 100
时,我得到:
5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
这是为什么? 这是我的代码
import math
KeepProgramRunning = True
while KeepProgramRunning:
print 'Please enter the centimetre value you wish to convert to millimetres '
a = raw_input()
print 'The answer is',
答案 0 :(得分:10)
那是因为raw_input()
返回一个字符串
使用int()
将该字符串转换为整数:
a = int(raw_input())
示例:
>>> x = raw_input()
2
>>> x * 5
'22222'
>>> x = int(raw_input())
2
>>> x * 5
10
答案 1 :(得分:7)
因为输入检索字符串,请按以下步骤操作:
import math
KeepProgramRunning = True
while KeepProgramRunning:
print 'Please enter the centimetre value you wish to convert to millimetres '
a = int(raw_input())
print 'The answer is',