Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.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_Python 3.x - Fatal编程技术网

Python 当我用逗号输入数字时,为什么这段代码会给我一个错误?

Python 当我用逗号输入数字时,为什么这段代码会给我一个错误?,python,python-3.x,Python,Python 3.x,整数不包含逗号,因此,如果您希望能够使用逗号输入数字,则需要在将字符串转换为整数之前将其去掉。例如,x=int(输入(“写入第一个数字”)。替换(“,”,”)。您可能希望接受分隔逗号的输入 x = int(input("Write the first number: ")) y = int(input("Write the second number: ")) 因为逗号不是整数?Python中的整数不包含逗号。整数作为字符串可以用于格式化,但当试图将变量的值设置为整数时,必须删除逗号。 x,

整数不包含逗号,因此,如果您希望能够使用逗号输入数字,则需要在将字符串转换为整数之前将其去掉。例如,
x=int(输入(“写入第一个数字”)。替换(“,”,”)

您可能希望接受分隔逗号的输入

x = int(input("Write the first number: "))

y = int(input("Write the second number: "))

因为逗号不是整数?Python中的整数不包含逗号。整数作为字符串可以用于格式化,但当试图将变量的值设置为整数时,必须删除逗号。
x,y=map(int,input('Enter two numbers seperated by comma').split(','))