Python Practice › Basic Programs › Program 11

Formula (a – b)² = a² + b² – 2ab

EasyBasic Programs · 11 of 40

Write a Python program to solve the formula (a – b)² = a² + b² – 2ab.

Advertisement
Input
a = 9, b = 4
Output
25 25 True

Approach

  1. Calculate both sides and compare them.

Solution

Python
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.

Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More basic programs

← All 40 Basic Programs