Question: You have to Create a class called Algebra, which has a single class variable called scale, and a constructor which takes two numerical values x

You have to Create a class called Algebra, which has a single class variable called scale, and a constructor which takes two numerical values x and y. The class should implement the following methods:

  1. Write a method called add which returns the sum of x and y.
  2. Write a class method called multiply, which takes a single number parameter a and return the product of a and scale.
  3. Write a static method called subtract, which takes two number parameters, b and c, and return b - c.
  4. Write a method called print_value, which prints the value of x and y, separated by a comma.

This learning activity requires you to write a program in Python.

Post a Python script file (.py) rather than copy and pasting your code into the text editor in discussion forum.

 

For example, please check the following solved answer. You can provide the answer here in that way or .py file 

 

class Algebra:
   scale = 2  

   def __init__(self, x, y):
       self.x = x
       self.y = y

   def add(self):
       return self.x + self.y

   @classmethod
   def multiply(cls, a):
       return a * cls.scale

   @staticmethod
   def subtract(b, c):
       return b - c

   def print_value(self):
       print(f"{self.x}, {self.y}")


algebra = Algebra(10, 20)
print("Sum:", algebra.add())  

a = 5
print("Product of a and scale:", Algebra.multiply(a))  

b, c = 20, 8
print("Difference:", Algebra.subtract(b, c))  

algebra.print_value()  

Step by Step Solution

3.55 Rating (165 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is a Python script that defines the Algebra class with the specified methods class Algebra scal... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!