Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
GreenGeeks Web Hosting - Faster, Scalable & Eco-Friendly

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Distribute your Resume to 500+ Job Boards & Recruiters


8,090 questions

11,268 answers

573 users

How to reducing fraction using class in Python

1 Answer

0 votes
class GetFraction(object):

    def __init__(self, number, denominator):
        self.numerator, self.denominator = GetFraction.reduce(number, denominator)

    @staticmethod
    def gcd(number, denominator):
        while denominator != 0:
            number, denominator = denominator, number % denominator
        return number

    @classmethod
    def reduce(cls, number, denominator):
        gcd_ = cls.gcd(number, denominator)
        return number // gcd_, denominator // gcd_

    def __str__(self):
        return str(self.numerator)+'/'+str(self.denominator)


x = GetFraction(7, 21)
print(x)

x = GetFraction(4, 16)
print(x)


'''
run:
 
1/3
1/4
 
'''

 




answered Feb 9 by avibootz
...