Skip to content

Commit 477a73f

Browse files
authored
Add files via upload
1 parent c0246f3 commit 477a73f

4 files changed

Lines changed: 112 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class animals:
2+
pass
3+
4+
class pets(animals):
5+
pass
6+
7+
class dog(pets):
8+
@staticmethod
9+
def bark():
10+
print("Woof! Woof!")
11+
12+
tom = dog()
13+
tom.bark()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class complex_number:
2+
def __init__(self, real, imag):
3+
self.real = real
4+
self.imag = imag
5+
6+
def complex_conjugate(self):
7+
print(f"The complex conjugate of \'{self.real} + {self.imag}i\' is \'{self.real} - {self.imag}i\'")
8+
9+
def __add__(self, other):
10+
return complex_number(self.real + other.real, self.imag + other.imag)
11+
12+
def __str__(self):
13+
return f"{self.real} + {self.imag}i"
14+
15+
def __sub__(self, other):
16+
return complex_number(self.real - other.real, self.imag - other.imag)
17+
18+
19+
s = complex_number(3, 4)
20+
r = complex_number(1, 2)
21+
22+
s.complex_conjugate()
23+
print(f"The sum of {s} and {r} is:", s + r)
24+
print(f"The difference of {s} and {r} is:", s - r)
25+
print(f"The difference of {r} and {s} is:", r - s)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class employee:
2+
salary = 10000
3+
increment = 37
4+
5+
@property
6+
def salary_with_increment(self):
7+
return f"Salary after increment is: {self.salary + (self.salary * self.increment / 100)}"
8+
9+
@salary_with_increment.setter
10+
def salary_with_increment(self, new_salary):
11+
self.increment = ((new_salary/self.salary) - 1) * 100
12+
13+
y = employee()
14+
# print(y.salary_with_increment)
15+
# print(y.increment)
16+
print(f"Salary is: {y.salary}")
17+
y.salary_with_increment = 30000
18+
print(f"Increment is: {y.increment}")
19+
print(y.salary_with_increment)
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
class _2D_vectors:
2+
def __init__(self, i, j):
3+
self.i = i
4+
self.j = j
5+
6+
def vectors(self):
7+
print(f"2D Vector is: {self.i}i + {self.j}j")
8+
9+
def magnitude(self):
10+
print(f"Magnitude of 2D vector is: {(self.i**2 + self.j**2) ** 0.5}")
11+
12+
def __str__(self):
13+
return f"{self.i}i + {self.j}j"
14+
15+
def __add__(self, other):
16+
return _2D_vectors(self.i + other.i, self.j + other.j)
17+
18+
def dot_product(self, other):
19+
return self.i * other.i + self.j * other.j
20+
21+
class _3D_vectors(_2D_vectors):
22+
def __init__(self, i, j, k):
23+
super().__init__(i, j)
24+
self.k = k
25+
26+
def vectors(self):
27+
print(f"3D Vector is: {self.i}i + {self.j}j + {self.k}k")
28+
29+
def magnitude(self):
30+
print(f"Magnitude of 3D vector is: {(self.i**2 + self.j**2 + self.k**2) ** 0.5}")
31+
32+
def __str__(self):
33+
return f"{self.i}i + {self.j}j + {self.k}k"
34+
35+
def dot_product(self, other):
36+
return self.i * other.i + self.j * other.j + self.k * other.k
37+
38+
def __add__(self, other):
39+
return _3D_vectors(self.i + other.i, self.j + other.j, self.k + other.k)
40+
41+
r = _2D_vectors(3, 4)
42+
r.vectors()
43+
r.magnitude()
44+
k = _2D_vectors(1, 2)
45+
print(f"The sum of {r} and {k} is:", r + k)
46+
print(f"The dot product of {r} and {k} is:", r.dot_product(k))
47+
48+
#-------------
49+
s = _3D_vectors(3, 4, 12)
50+
s.vectors()
51+
s.magnitude()
52+
p = _3D_vectors(1, 2, 5)
53+
print(f"The sum of {s} and {p} is:", s + p)
54+
print(f"The dot product of {s} and {p} is:", s.dot_product(p))
55+
print(f"The dot product of {r} and {s} is:", r.dot_product(s))

0 commit comments

Comments
 (0)