Skip to content

Commit 6bef3c4

Browse files
first commit
1 parent 9ee1591 commit 6bef3c4

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

fraction.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
class Fraction():
2+
def __init__(self, num, den = 1):
3+
if den < 0:
4+
new_num = -num
5+
new_den = -den
6+
self.nr = new_num
7+
self.dr = new_den
8+
else:
9+
self.nr = num
10+
self.dr = den
11+
12+
def multiply1(self, nr1, nr2, dr1 = 1, dr2 = 1):
13+
# self.nr = nr1 * nr2
14+
# self.dr = dr1 * dr2
15+
product = self * fraction
16+
return product
17+
18+
def multiply(self, fraction):
19+
new_nr = self.nr * fraction
20+
new_dr = fraction / self.dr
21+
product = Fraction(new_nr, new_dr)
22+
return product.display()
23+
24+
def display(self):
25+
print(self.nr, "/", self.dr)
26+
27+
fr = Fraction(2,-3)
28+
fr.display()
29+
product = fr.multiply(2/3)
30+
print("product", product)

product.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Product():
2+
def __init__(self, id, marked_price, discount):
3+
self.id = id
4+
self.marked_price = marked_price
5+
self.discount = discount
6+
7+
@property
8+
def selling_price(self):
9+
return self.marked_price - ((self.discount/100) * self.marked_price)
10+
11+
@property
12+
def discount(self):
13+
return self._discount + 2 if self.marked_price > 500 else self._discount
14+
15+
@discount.setter
16+
def discount(self, new_discount):
17+
self._discount = new_discount
18+
19+
def display(self):
20+
print(self.id, self.marked_price, self.discount)
21+
22+
p1 = Product('X879', 400, 6)
23+
p2 = Product('A234', 100, 5)
24+
p3 = Product('B987', 990, 4)
25+
p4 = Product('H456', 800, 6)
26+
print(p1.selling_price)
27+
print(p3.discount)
28+
p4.display()

0 commit comments

Comments
 (0)