Python Practice › Basic Programs › Program 12
Formula a² – b² = (a – b)(a + b)
Write a Python program to solve the formula a² – b² = (a – b)(a + b).
Input
a = 10, b = 6
Output
64 64 True
Approach
- Calculate both sides and compare them.
Solution
a = 10b = 6 left = a ** 2 - b ** 2right = (a - b) * (a + b)print(left, right, left == right)Output
64 64 True
Line by line
Lines 4-5
100 – 36 and 4 × 16 both give 64. Python does not multiply brackets automatically, so the * between them is required.
Learn the concept
New to this topic? Read the lesson, then come back.