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!