Home  >  Article  >  Backend Development  >  How to output quotient and remainder in python

How to output quotient and remainder in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-11 14:57:4915621browse

How to output quotient and remainder in python

How does python output the quotient and remainder? Here are two methods to introduce to you:

Method 1:

You can use // to find the quotient and % of dividing two numbers. Get the remainder after dividing two numbers. [/What is obtained in Python is the result of division, usually a floating point number]

a = int(input(u"输入被除数: "))
b = int(input(u"输入除数:"))

Running result

输入被除数: 100 
输入除数:30

Method 2:

Use the divmod() function to obtain the ancestor composed of the quotient and the remainder

div = a // b 
mod = a % b 
print("{} / {} = {} ... {}".format(a, b, div, mod))
print("{} / {} = {} ... {}".format(a, b, *divmod(a, b)))

Running results

100 / 30 = 3 … 10 
100 / 30 = 3 … 10

The above is the detailed content of How to output quotient and remainder in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn