例如,当我进入时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',
Run Code Online (Sandbox Code Playgroud)
Ash*_*ary 10
那是因为raw_input()返回一个字符串
使用int()该字符串转换为整数:
a = int(raw_input())
Run Code Online (Sandbox Code Playgroud)
例:
>>> x = raw_input()
2
>>> x * 5
'22222'
>>> x = int(raw_input())
2
>>> x * 5
10
Run Code Online (Sandbox Code Playgroud)
因为输入检索字符串,请执行以下操作:
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',
Run Code Online (Sandbox Code Playgroud)