ScholarMatic | 24/7 Homework Help

ScholarMatic Will Help You Write Your Essays and Term Papers

Answered » You can buy a ready-made answer or pick a professional tutor to order an original one.

You are given two complex numbers. You will print the result of their addition, subtraction, multiplication, division, and modulus operations.

ScholarMatic: Explanation & Answer

Your ready answer from a verified tutor is just a click away for as little as $14.99


  

Click Order Now to get 100% Original Answer Customized to your instructions!

You are given two complex numbers. You will print the result of their addition, subtraction, multiplication, division, and modulus operations. The real and imaginary precision part should be correct up to two decimal places.

Input Format 

One line of input: The real and imaginary part of a number separated by a space.

Output Format 

For two complex numbers and the output should be in the following sequence on separate lines:

  • C + D
  • C – D
  • C * D
  • C / D
  • mod(C)
  • mod(D)

For complex numbers with non-zero real and complex part, the output should be in the following format: 

A + Bi

Replace the plus symbol (+) with a minus symbol (-) when B < 0.

For complex numbers with a zero complex part, i.e. real numbers, the output should be: 

A + 0.00i

For complex numbers where the real part is zero and the complex part is non-zero, the output should be:

0.00 + Bi

Sample Input 

2 1

5 6

Sample Output 

7.00+7.00i

-3.00-5.00i

4.00+17.00i

0.26-0.11i

2.24+0.00i

7.81+0.00i

Assignment Instructions

  • Need a Complex class to perform the processing. Use the following code template.

import math

class Complex(object):

    def __init__(self, real, imaginary):

        self.real = real

        self.imaginary = imaginary

    def __add__(self, no):

        # enter your code here 

        return Complex(real, imaginary)

    def __sub__(self, no):

        # enter your code here        

        return Complex(real, imaginary)

    def __mul__(self, no):

        # enter your code here

        return Complex(real, imaginary)

    def __div__(self, no):

        # enter your code here

        return Complex(real, imaginary)

    def mod(self):

        # enter your code here

        return Complex(real, 0)

    def __str__(self):

        # enter your code here

        return result

# put this code in a main method

C = map(float, raw_input().split())

D = map(float, raw_input().split())

x = Complex(*C)

y = Complex(*D)

print ‘n’.join(map(str, [x+y, x-y, x*y, x/y, x.mod(), y.mod()]))

  • Develop Python code that implements the program requirements.
ScholarMatic: Explanation & Answer

Your ready answer from a verified tutor is just a click away for as little as $14.99


  

Click Order Now to get 100% Original Answer Customized to your instructions!

HOME TO CERTIFIED WRITERS

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing

Have a similar question?

PLAGIRAISM FREE PAPERS

All papers we provide are well-researched, properly formatted and cited.

TOP QUALITY

All papers we provide are well-researched, properly formatted and cited.

HIGHLY SECURED

All papers we provide are well-researched, properly formatted and cited.

ScholarMatic: Get Started

Assignment Writing Service

Feel safe and secure when placing an order on our portal!
Fruitful cooperation begins with solid guarantees, and we are professional enough to promise perfect results. Let’s get it started!