# Python percentage difference between two numbers | Example code

You have to use a math formula to find the percentage difference between two numbers in Python.

Formula to calculate percentage:

``(Percentage2 – Percentage1) * 100 / (Percentage1) ``

## Example percentage difference between two numbers in Python

Simple example code finds the percentage of the difference between two numbers.

``````a = 10
b = 15

result = int(((b - a) * 100) / a)

print(result, "%")``````

Output: 50 %

User input number

``````first = int(input("Enter first number: "))
second = int(input("Enter second number:"))

res = ((first - second) / first) * 100

print("Difference in percentage is : {}%".format(res))
``````

Output:

Do comment if you have any doubts or suggestions on this Python number topic.

Note: IDE: PyCharm 2021.3 (Community Edition)

Windows 10

Python 3.10.1

All Python Examples are in Python 3, so Maybe its different from python 2 or upgraded versions.

This site uses Akismet to reduce spam. Learn how your comment data is processed.