Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将浮点和整数相加,取绝对值_Python_Floating Point_Integer_Addition_Absolute Value - Fatal编程技术网

Python 将浮点和整数相加,取绝对值

Python 将浮点和整数相加,取绝对值,python,floating-point,integer,addition,absolute-value,Python,Floating Point,Integer,Addition,Absolute Value,您好,我对代码非常陌生,我需要知道如何输出通过计算| x+y |得到的值,其中x是浮点,y是整数,这两种输入都是未知的。我尝试过很多事情,但都没有成功,请帮助我 这就是我现在所拥有的,但我知道这是非常错误的:(在大多数情况下,在尝试操作时,我会得到错误TypeError:不支持的+操作数类型:'int'和'str' 这是我最近的一次尝试: x = int(input()) y = input() w = (x + y) print (abs(w)) 您需要将y转换为: 函数从文档中返回一

您好,我对代码非常陌生,我需要知道如何输出通过计算| x+y |得到的值,其中x是浮点,y是整数,这两种输入都是未知的。我尝试过很多事情,但都没有成功,请帮助我

这就是我现在所拥有的,但我知道这是非常错误的:(在大多数情况下,在尝试操作时,我会得到错误
TypeError:不支持的+操作数类型:'int'和'str'
这是我最近的一次尝试:

x = int(input())

y = input()

w = (x + y)

print (abs(w))

您需要将
y
转换为:

函数从文档中返回一个字符串:

如果存在提示参数,则将其写入标准输出 没有尾随的换行符。然后函数从输入中读取一行, 将其转换为字符串

x = int(input())
y = float(input())
w = (x + y)
print(abs(w))