0

例如,当我输入时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', 
4

2 回答 2

10

那是因为raw_input()返回一个字符串

用于int()将该字符串转换为整数:

a = int(raw_input())

例子:

>>> x = raw_input()
2
>>> x * 5
'22222'
>>> x = int(raw_input())
2
>>> x * 5
10
于 2012-10-10T18:12:50.497 回答
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', 
于 2012-10-10T18:13:21.160 回答