Python Practice › Basic Programs › Program 11
Formula (a – b)² = a² + b² – 2ab
Write a Python program to solve the formula (a – b)² = a² + b² – 2ab.
Input
a = 9, b = 4
Output
25 25 True
Approach
- Calculate both sides and compare them.
Solution
a = 9b = 4 left = (a - b) ** 2right = a ** 2 + b ** 2 - 2 * a * bprint(left, right, left == right)Output
25 25 True
Line by line
Line 4
(a - b) 2 is 5 2.
Line 5
The expanded form gives the same value, 25.
Learn the concept
New to this topic? Read the lesson, then come back.