0

I am trying to Implement a child class called mathnew and parent classes as sqroot, addition, subtraction, multiplication and division. Use the super() function to inherit the parent methods.

This is the code.

from math import *
from functools import reduce

class sqroot:

    def __init__(self,n1):
        self.n1 = n1

    def sqroot(self):
        return(sqrt(self.n1))

class addition:

    def __init__(self,n2):
        self.n = n2

    def add(self):
        return(sum(self.n))


class subtraction:

    def __init__(self,n3,n4):
        self.n1 = n3
        self.n2 = n4

    def sub(self):
        return((self.n1-self.n2))

class multiplication:

    def __init__(self,n5):
        self.n = n5

    def product(self):
        return((reduce(lambda x,y: x*y, self.n)))

class division:

    def __init__(self,n6,n7):
        self.n1 = n6
        self.n2 = n7

    def div(self):
        return("The quotient is :- {}".format(self.n1/self.n2))


class mathnew(sqroot,addition,subtraction,multiplication,division):
    def __init__(self):
        super().__init__()


d1 = mathnew(4)
print(d1.sqroot(4))

I tried multiple ways but it is not working

1 Answer 1

1

Try this:

import math


class sqroot:
    def sqroot(self,a):
        print(math.sqrt(a))


class addition:
    def add(self,a,b):
        print(a+b)


class subtraction:
    def sub(self,a,b):
        print(a-b)


class multiplication:
    def mult(self,a,b):
        print(a*b)


class division:
    def div(self,a,b):
        print(a/b)


class mathnew(sqroot, addition, subtraction, multiplication, division):
    def __init__(self):
        super()


m = mathnew()

m.sqroot(4)
m.add(4,5)
m.sub(5,8)
m.mult(5,6)
m.div(47,2)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.