Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.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,除了这两个,其他一切都很好 People = input("Number of people: ") Cookie = input("Numnber of cookies: ") People = int(People) Answer = int(Cookie) / int(People) Remain = int(Cookie) % int(People) print ("Cookies per person: ", Answer) print ("Cookies returning to t

除了这两个,其他一切都很好

People = input("Number of people: ")
Cookie = input("Numnber of cookies: ")
People = int(People)
Answer = int(Cookie) / int(People)
Remain = int(Cookie) % int(People)
print ("Cookies per person: ", Answer)
print ("Cookies returning to the jar: ", Remain)
使用两个变量4(人)和11(cookies)运行代码将返回以下结果:

Number of people: 4
Number of cookies: 11
Cookies per person:  2.75
Cookies returning to the jar:  3
如何将2.75改为2


Python3.3要恢复Python2.X的
int
行为,您可以使用
/

>>> 11/4
2.75
>>> 11//4
2

因此,
/
也适用于Python 2。

在本例中,您还可以使用更简洁的:

answer, remain = divmod(cookies, people)