>>> x =input("x:") x:34 >>> y =input("y:") y:42 >>> print x * y SyntaxError:invalid syntax哪里错了啊
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/24 04:35:14
>>> x =input("x:") x:34 >>> y =input("y:") y:42 >>> print x * y SyntaxError:invalid syntax哪里错了啊
>>> x =input("x:") x:34 >>> y =input("y:") y:42 >>> print x * y SyntaxError:invalid syntax
哪里错了啊
>>> x =input("x:") x:34 >>> y =input("y:") y:42 >>> print x * y SyntaxError:invalid syntax哪里错了啊
这里因为你的python版本应该是3以上,3以上你获取的x,y是str,2.7是int,所以你要int(x)*int(y),
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x =input("x:")
x:34
>>> y =input("y:")
y:42
>>> x
34
>>> y
42
>>> print x*y
1428
Python 3.2.3 (default, Sep 30 2012, 16:41:36)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x =input("x:")
x:34
>>> y =input("y:")
y:42
>>> x
'34'
>>> y
'42'
>>> int(x)
34
>>> int(y)
42
>>> int(x) * int(y)
1428
>>> print(int(x) * int(y))
1428