How to output quotient and remainder in python

爱喝马黛茶的安东尼
Release: 2019-06-19 13:33:11
Original
15760 people have browsed it

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"输入除数:"))
Copy after login

Running result

输入被除数: 100 
输入除数:30
Copy after login

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)))
Copy after login

Running results

100 / 30 = 3 … 10 
100 / 30 = 3 … 10
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template