Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions 1- Create the class Society.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class society:
def __init__(self, society_name, house_no, no_of_members, income):
self.society_name = society_name
self.house_no = house_no
self.no_of_members = no_of_members
self.income = income
self.allocate_flat()

def inputdata(self):
self.society_name = input("Enter Society Name:")
self.house_no = input("Enter House Number:")
self.no_of_members = input("Enter No of members:")
self.income = float(input("Enter income:"))
self.allocate_flat()

def complete(self):
return f"society_name: {self.society_name} house_no: {self.house_no} no_of_members: " \
f"{self.no_of_members} income: {self.income} flat type: {self.flat} "

def allocate_flat(self):
if self.income >= 25000:
self.flat = "AType"

elif 20000 <= self.income < 25000:
self.flat = "BType"

elif 15000 <= self.income < 20000:
self.flat = "CType"

else:
self.flat = "DType"

def showdata(self):
print("Society Name", self.society_name)
print("House_No", self.house_no)
print("No.of members", self.no_of_members)
print("Flat Type", self.flat)
print("Income", self.income)


S = society("a", "b", "c", 10000)

S.showdata()

print(S.complete())

54 changes: 54 additions & 0 deletions 2- Define a class named ItemInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
class ItemInfo:
item_code = 0
price = None
qty = None
Net_price = None
discount = None

def __init__(self):
self.item_code = 0
self.price = None
self.qty = None
self.net_price = None
self.discount = None

def buy(self):
self.item_code = int(input("Please enter an item code: "))
self.item = input("Please enter an item name: ")
self.price = int(input("Please enter a price: "))
self.qty = int(input("Please enter quantity: "))

def calculate_discount(self):
if self.qty <= 10:
self.discount = 0
if 11 <= self.qty < 20:
self.discount = 15
if self.qty > 20:
self.discount = 20

def show_all(self):
print("item_code: " +
str(self.item_code) + " price: " +
str(self.price) + " quantity: " +
str(self.qty) + " net price: " +
str(self.net_price) + " discount" +
str(self.discount)
)

def net_price_calculate(self):
self.net_price = ((self.price * self.qty) * (100 - self.discount)) / 100


S = ItemInfo()
S.buy()
S.calculate_discount()
S.net_price_calculate()
S.show_all()
S.buy()
S.calculate_discount()
S.net_price_calculate()
S.show_all()
S.buy()
S.calculate_discount()
S.net_price_calculate()
S.show_all()
38 changes: 38 additions & 0 deletions 3-Define a class named Product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Product:
product_id = 0
product_name = "None"
product_purchase_price = 0
product_sale_price = 0
remarks = "None"

def __int__(self):
self.product_id = 0
self.product_name = "None"
self.product_purchase_price = 0
self.product_sale_price = 0
self.remarks = "None"

def set_remarks(self):
if self.product_sale_price - self.product_purchase_price > 0:
self.remarks = "Profit"
elif self.product_sale_price - self.product_purchase_price < 0:
self.remarks = "Loss"

def set_details(self, product_id, product_name, product_purchase_price, product_sale_price):
self.product_id = product_id
self.product_name = product_name
self.product_purchase_price = product_purchase_price
self.product_sale_price = product_sale_price
self.set_remarks()

def get_details(self):
print("\n Product id: " + str(self.product_id) + "\n Product name: " + self.product_name + "\n Product Purchase Price: " +
str(self.product_purchase_price) + "\n Product Sale Price " + str(
self.product_sale_price) + "\n Remarks: " + self.remarks)


Example_class = Product()
Example_class.set_details(1, "pen", 10, 12)
Example_class.get_details()
Example_class.set_details(2, "notebook", 10, 8)
Example_class.get_details()
118 changes: 118 additions & 0 deletions 4- Write a Customer class and Items class.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
class Items:
item_name = "new"
item_price = 0

def __init__(self, item_name, item_price):
self.item_name = item_name
self.item_price = item_price

def get_price(self):
return self.item_price


class Customer:
customer_id = 0
name = "name"
lastname = "lastname"

def __init__(self, customer_id, name, lastname):
self.customer_id = customer_id
self.name = name
self.lastname = lastname


class Shopping_Card:
one_customer = None
line_item_list = []

def __init__(self, customer):
assert isinstance(customer, Customer)
self.one_customer = customer
self.line_item_list = []

def __str__(self):
text = self.one_customer.name + " " + self.one_customer.lastname + " " + \
str(self.one_customer.customer_id) + "\n" + \
"YOUR SHOPPING CARD" + "\n_______________________________\n\n"


for line_item in self.line_item_list:
item = line_item["product"]
assert isinstance(item, Items)
text = text + item.item_name + " x " + str(line_item["count"]) + " " + str(line_item["count"] * item.item_price) + "\n"

text = text + "\nSUB TOTAL " + str(self.total_price())
text = text + "\nDISCOUNT " + str(self.total_price()*self.calculate_discount()/100) + " %" + str(self.calculate_discount())
text = text + "\n_______________________________"
text = text + "\nTOTAL " + str(self.price_to_be_paid())
return text

def create_line_item(self, item, count):
assert isinstance(item, Items)
line_item_dict = dict()
line_item_dict["product"] = item
line_item_dict["count"] = count
self.line_item_list.append(line_item_dict)

def total_price(self):
total_price = 0
for line_item_dict in self.line_item_list:
item = line_item_dict["product"]
# assert isinstance(item, Items)
total_price = total_price + line_item_dict["count"] * item.get_price()
return total_price

def calculate_discount(self):
total_price = self.total_price()
if total_price >= 4000:
return 25
elif total_price >= 2000:
return 15
elif total_price < 2000:
return 10

def price_to_be_paid(self):
discount = self.calculate_discount()
total_price = self.total_price()
return (total_price*(100-discount))/100


class Shop:
items_list = []
customer_list = []
shopping_card_list = []


shop = Shop

t_shirt = Items("t-shirt ", 100)
shirt = Items("shirt ", 300)
shoes = Items("shoes ", 500)
pant = Items("pant ", 400)

customer_1 = Customer(1001, "John", "Traolta")
shop.customer_list.append(customer_1)
customer_2 = Customer(1002, "Coby", "Brien")
shop.customer_list.append(customer_2)
customer_3 = Customer(1003, "Micheal", "Dan")
shop.customer_list.append(customer_3)
customer_4 = Customer(1004, "Susan", "Farrel")
shop.customer_list.append(customer_4)

new_shop_card = Shopping_Card(customer_1)
shop.shopping_card_list.append(new_shop_card)
new_shop_card.create_line_item(t_shirt, 2)
new_shop_card.create_line_item(shirt, 3)
new_shop_card.create_line_item(shoes, 2)
new_shop_card.create_line_item(pant, 5)

new_shop_card2 = Shopping_Card(customer_2)
new_shop_card2.create_line_item(t_shirt, 3)
new_shop_card2.create_line_item(shirt, 1)
new_shop_card2.create_line_item(shoes, 1)
new_shop_card2.create_line_item(pant, 2)


print(new_shop_card)

print(new_shop_card2)