python第二版中 获取用户输入 input函数中最后使用x * y提示这个! 小生初学,求大神指导!

2025-02-23 10:17:47
推荐回答(3个)
回答1:

# python 2.x 中可以写成print xxx可以带括号, 也可以不带
# python 3.x 中必须写成print(xxx)必须带括号
print xxx

注意看版本号2.7.6

3.4.3

回答2:

Python 2.7.9 (default, Mar  8 2015, 00:52:26) 
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x=input("x: ")
x: 42
>>> y=input("y: ")
y: 34
>>> print x * y
1428
>>>
Python 3.4.2 (default, Oct 19 2014, 13:31:11) 
[GCC 4.9.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = input (":")
:42
>>> y=input(":")
:34
>>> print (x*y)
Traceback (most recent call last):
  File "", line 1, in 
TypeError: can't multiply sequence by non-int of type 'str'
>>> print(int(x) * int(y))
1428
>>>

回答3:

你既然是键盘输入给X,Y赋值,就不要在里面给他个数字啊,你这等于”x=x:34“和”y=y:42“
你算乘法怎么也算出不来啊
x:34*y:42=?