circle,Rational Number

UpComing SoftWare Training Demos

๐Ÿš€ *Playwright With AI Testing Demo In Telugu*
๐Ÿ—“๏ธ *Date:* 28 Oct2026, 08:00 PM IST
๐Ÿ“ *Register Now!:*
https://www.vlrt.in/3r
๐Ÿ‘ฅ *Join WA Community:*
https://www.vlrt.in/3w
๐Ÿ’ก *Course Content:*
https://www.vlrt.in/3c
โ–ถ๏ธ *Demo Videos:*
https://www.vlrt.in/3v

๐Ÿš€ *Gen AI Engineer (Production Focused)*
๐Ÿ—“๏ธ *Date:* 29th Oct 2026, 06:00PM IST
๐Ÿ“ *Register Now!:*
https://www.vlrt.in/gr
๐Ÿ‘ฅ *Join WA Community:*
https://www.vlrt.in/gw
๐Ÿ’ก*Course Content:*
https://www.vlrt.in/ai
โ–ถ๏ธ *Demo Videos:*
https://www.vlrt.in/gv

๐Ÿš€ *Vulnerability Management Training Demo*
๐Ÿ—“๏ธ *Date:* 28th Oct 2026, 10:00 AM IST
๐Ÿ“*Register Now!:*
https://www.vlrt.in/vr
๐Ÿ‘ฅ *Join Community:*
https://www.vlrt.in/cw
๐Ÿ’ก *Course Content:*
https://www.vlrt.in/vc
โ–ถ๏ธ *Demo Videos:*
https://www.vlrt.in/Vm

import math

class Circle:
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return math.pi * self.radius * self.radius

    def perimeter(self):
        return 2 * math.pi * self.radius
    

c1 = Circle(7)
print('Area:',c1.area())
print('Perimeter:',c1.perimeter())

1. What is a Rational Number?

A rational number is any number that can be expressed as a fraction where both the numerator and the denominator are integers (whole numbers), and the denominator is not zero.

The key idea is ratio. The word “rational” comes from the word “ratio.”

General Form:
a / b

  • aย is theย numeratorย (an integer)
  • bย is theย denominatorย (an integer, andย b โ‰  0)

Examples:

  • 1/2,ย 3/4,ย -5/7ย (Simple fractions)
  • 5ย (because it can be written asย 5/1)
  • 0ย (because it can be written asย 0/1)
  • -3ย (because it can be written asย -3/1)
  • 0.75ย (because it can be written asย 3/4)
  • 0.333...ย (because it can be written asย 1/3)

Non-Examples:

  • ฯ€ (Pi)ย – It cannot be expressed as a simple fraction of two integers. Its decimal expansion is non-terminating and non-repeating.
  • โˆš2 (Square root of 2)ย – It also cannot be expressed as a simple fraction of two integers.

2. Formulas for Addition and Subtraction

The most important rule for adding and subtracting rational numbers is that they must have a common denominator.

Let our two rational numbers be:
a / b and c / d
where a, b, c, d are integers, and b โ‰  0, d โ‰  0.

Formula for Addition:

(a/b) + (c/d) = (aร—d + cร—b) / (bร—d)

Step-by-step reasoning:

  1. Find a common denominator. The easiest one is the product of the two denominators:ย b ร— d.
  2. Adjust the first fraction:ย (a/b)ย becomesย (aร—d)/(bร—d).
  3. Adjust the second fraction:ย (c/d)ย becomesย (cร—b)/(bร—d).
  4. Now that the denominators are the same, add the numerators:ย (aร—d + cร—b).
  5. Place the result over the common denominator.

Example: Add 1/2 and 1/3

  • a=1, b=2, c=1, d=3
  • Using the formula:ย (1/2) + (1/3) = (1ร—3 + 1ร—2) / (2ร—3) = (3 + 2) / 6 = 5/6

Formula for Subtraction:

(a/b) – (c/d) = (aร—d – cร—b) / (bร—d)

The process is identical to addition, except you subtract the numerators.

Step-by-step reasoning:

  1. Find the common denominator:ย b ร— d.
  2. Adjust the first fraction:ย (aร—d)/(bร—d).
  3. Adjust the second fraction:ย (cร—b)/(bร—d).
  4. Subtract the numerators:ย (aร—d - cร—b).
  5. Place the result over the common denominator.

Example: Subtract 1/3 from 1/2

  • a=1, b=2, c=1, d=3
  • Using the formula:ย (1/2) - (1/3) = (1ร—3 - 1ร—2) / (2ร—3) = (3 - 2) / 6 = 1/6

Important Note: Simplifying the Result

After you calculate the sum or difference, always check if the resulting fraction can be simplified.

For example, if you add 1/4 + 1/4:

  • (1ร—4 + 1ร—4) / (4ร—4) = (4+4)/16 = 8/16
  • The resultย 8/16ย can be simplified by dividing the numerator and denominator by their greatest common divisor (8), giving you the final answer:ย 1/2.

Summary

OperationFormulaExample
Addition(a/b) + (c/d) = (ad + bc)/(bd)1/2 + 1/3 = (3+2)/6 = 5/6
Subtraction(a/b) - (c/d) = (ad - bc)/(bd)1/2 - 1/3 = (3-2)/6 = 1/6

class Rational:

    def __init__(self, p, q):
        self.p = p
        self.q = q

    def __add__(self, other):
        p = self.p * other.q + self.q * other.p
        q = self.q * other.q
        sum = Rational(p,q)
        return sum

    def __sub__(self, other):
        p = self.p * other.q - self.q * other.p
        q = self.q * other.q
        sum = Rational(p, q)
        return sum

    def __str__(self):
        return str(self.p) + '/' + str(self.q)


r1 = Rational(2,3)
r2 = Rational(1,2)

r3 = r1 + r2

print(r1, '+', r2, '=', r3)

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *