Python Practice › Basic Programs › Program 12

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

EasyBasic Programs · 12 of 40

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

Advertisement
Input
a = 10, b = 6
Output
64 64 True

Approach

  1. Calculate both sides and compare them.

Solution

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

Advertisement

Learn the concept

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

More basic programs

← All 40 Basic Programs