在 Python 中获取用户输入是一个非常基本的疑问,Python 是否将任何输入作为字符串并将其用于计算,我们必须将其更改为整数还是什么?在以下代码中:
a = raw_input("Enter the first no:")
b = raw_input("Enter the second no:")
c = a + b
d = a - b
p = a * b
print "sum =", c
print "difference = ", d
print "product = ", p
Python给出以下错误:
Enter the first no:2
Enter the second no:4
Traceback (most recent call last):
File "C:\Python27\CTE Python Practise\SumDiffProduct.py", line 7, in <module>
d=a-b
TypeError: unsupported operand type(s) for -: 'str' and 'str'
有人可以告诉我为什么会收到此错误吗?