Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
52 lines (33 loc) · 1.18 KB

File metadata and controls

52 lines (33 loc) · 1.18 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Author : Pavankumar Hegde
# Question : Complex Number Class
# Question Link : https://www.codingninjas.com/codestudio/guided-paths/basics-of-python/content/118797/offering/1467359
# Solution
class ComplexNumbers:
def __init__(self,real,imaginary):
self.real = real
self.imaginary = imaginary
def plus(self,c):
real = self.real + c.real
imaginary = self.imaginary + c.imaginary
self.real = real
self.imaginary = imaginary
def multiply(self,c):
real = (self.real * c.real) - (self.imaginary * c.imaginary)
imaginary = (self.real * c.imaginary) + (self.imaginary * c.real)
self.real = real
self.imaginary = imaginary
def print(self):
print(str(self.real) + " + " + "i" + str(self.imaginary))
real1,imaginary1 = map(int,input().split(' '))
real2,imaginary2 = map(int,input().split(' '))
C1 = ComplexNumbers(real1,imaginary1)
C2 = ComplexNumbers(real2,imaginary2)
choice = int(input())
if(choice == 1):
C1.plus(C2)
C1.print()
elif choice == 2:
C1.multiply(C2)
C1.print()
else:
pass
Morty Proxy This is a proxified and sanitized view of the page, visit original site.