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
93 changes: 93 additions & 0 deletions CustomerItems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'''
Write a Customer class and Items class. Let user enter customer information and add stuff to his/her
shopping card.
Class Items :
Method : __init__(), __str__(), calculate_discount(), shopping_cart(), get_total_amount()
calculate_discount():
total_price = price * qty
discount —> 25% if total_price >= 4000
discount —> 15% if total_price >= 2000
discount —> 10% if total_price < 2000
price_tobe_paid = total_price – discount
shopping_cart():
Let user add items in the shopping basket. Be creative with the items, set their prices as well.
__str__():
Print items added and total price nicely.
Class Customer :
Methods: __init__(), get_cust_info() this is optional, __str__()
Optionally create a get_cust_info() or similar to allow customer to enter his/her information or
just define them in __init__() and pass customer information as arguments while creating a customer object.
__str__():
Print customer information and price nicely.
Find a way to link two classes. For example, instances of both classes may have a customer number.
With a get method, get the customer number and pass it to the item object as an argument to
set customer number attribute. So Customer class instance holds the customer info, Items class holds
the shopped item’s info for the same customer ID number such as price, quantity or so.
In the end, print both info (customer info and shopped items info) using their respective __str__ format
in a nice way.
Simple example:
Customer1 = [name : Jack, last_name : Russel, customer_id : 123]
shopping_cart1 = [customer_id : 123, items : [necklace, ring, ear ring], total_price : 2000,
discount : 300, price_tobe_paid : 1700]
Author= Bulent Caliskan date= 08/02/2021
'''
class Items:

def __init__(self,item_name,price,qty,total_price,price_tobe_paid):
self.item_name = item_name
self.price = price
self.qty = qty
self.total_price=total_price
self.price_tobe_paid = price_tobe_paid
def shopping_cart(self):

self.item_name=input("Enter item name? ")
self.price=int(input("Enter price of item? "))
self.qty=int(input("Enter quantity of item? "))

def __str__(self):
print (f"Item name : {self.item_name}\
\n{self.item_name} price : {self.price}\
\nQuantity of item : {self.qty}\
\nDiscount : {Items.calculate_discount(self):.5}\
\nPrice to be paid : {Items.get_total_amount(self)}")


def calculate_discount(self):
self.total_price = self.price * self.qty
if self.total_price >= 4000 : return self.total_price*0.25
elif self.total_price >= 2000 : return self.total_price*0.15
elif self.total_price < 2000 : return self.total_price*0.10



def get_total_amount(self):
self.price_tobe_paid=self.total_price-Items.calculate_discount(self)
return self.price_tobe_paid


class Customer:
def __init__(self,customer_name,customer_surname,customer_id):
self.customer_name = customer_name
self.customer_surname = customer_surname
self.customer_id = customer_id

def get_cust_info(self):
self.customer_name=input("Enter your name? ")
self.customer_surname=input("Enter your surname? ")
self.customer_id=int(input("Enter your customer ID? "))

def __str__(self):
print (f"Name : {self.customer_name}\
\nSurname : {self.customer_surname}\
\nCustomer ID : {self.customer_id}")


customer1=Customer(0,0,0)
customer1.get_cust_info()

item1=Items(0,0,0,0,0)
item1.shopping_cart()

customer1.__str__()
item1.__str__()
57 changes: 57 additions & 0 deletions ItemInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'''
Define a class named ItemInfo with the following description:
item_code(Item Code), item(item name), price(Price of each item), qty(quantity in stock),
discount(Discount percentage on the item), net_price(Price after discount)
Methods :
A member method calculate_discount() to calculate discount as per the following rules:
If qty <= 10 —> discount is 0
If qty (11 to 20 inclusive) —> discount is 15
If qty >= 20 —> discount is 20
A constructor init method to assign the initial values for item_code to 0 and price, qty,
net_price and discount to null
A function called buy() to allow user to enter values for item_code, item, price, qty.
Then call function calculate_discount() to calculate the discount and net_price(price * qty - discount).
A function show_all() or similar name to allow user to view the content of all the data members.
Author= Bulent Caliskan date= 08/02/2021
'''
class ItemInfo:
def __init__(self,item_code,item,price,qty,discount,net_price):
self.item_code = item_code
self.item = item
self.price = price
self.qty = qty
self.discount = discount
self.net_price = net_price

def calculate_discount(self):
if self.qty<=10: return 0
elif 11<self.qty<20: return 15
else: return 20

def buy(self):
try:
self.item_code = int(input("Enter code of item ? "))
self.item = input("Enter name of item ? ")
self.price = int(input("Enter price of each item ? "))
self.qty = int(input("Enter quantity in stock ? "))
self.net_price=(self.price*self.qty)- ItemInfo.calculate_discount(self)
except:print("Please enter the value you entered correctly. ")

def show_all(self):
print(f"Item Code : {self.item_code}\
\nItem name : {self.item}\nItem price : {self.price}\
\nQuantity in stock : {self.qty}\nNet Price : {self.net_price} ")


item1= ItemInfo(0,0,0,0,0,0)
item2= ItemInfo(0,0,0,0,0,0)

item1.buy()
item1.show_all()

item2.buy()
item2.show_all()




60 changes: 60 additions & 0 deletions Product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
'''
Define a class named Product with the following specifications:
Data members:
product_id – A string to store product.
product_name - A string to store the name of the product.
product_purchase_price – A decimal to store the cost price of the product.
product_sale_price – A decimal to store Sale Price Margin - A decimal to be calculated as
(product_sale_price - product_purchase_price)
Remarks - To store "Profit" if Margin is positive else "Loss" if Margin is negative.
Methods :
A constructor to intialize all the data members with valid default values.
A method set_remarks() that assigns Margin as (product_sale_price - product_purchase_price) and
sets Remarks as mentioned below :
Margin Remarks
<0 negative Loss
>0 positive Profit
A method set_details() to accept values for product_id. product_name, product_purchase_price,
product_sale_price and invokes SetRemarks() method.
A method get_details() that displays all the data members.
Author= Bulent Caliskan date= 08/02/2021
'''


class Product:
def __init__(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

def set_remarks(self):
if (self.product_sale_price - self.product_purchase_price) < 0: return "Loss"
else: return "Profit"

def set_details(self):
try:
self.product_id = input("Enter id of product ? ")
self.product_name = input("Enter name of product ? ")
self.product_purchase_price = int(input("Enter product purchase price ? "))
self.product_sale_price = int(input("Enter product sale price ? "))

except:
print("Please enter the value you entered correctly. ")

def get_details(self):
print (f"Product ID : {self.product_id}\
\nProduct name : {self.product_name}\
\nProduct purchase price : {self.product_purchase_price}\
\nProduct sale price : {self.product_sale_price}\
\nSale price margin : {Product.set_remarks(self)} ")


product1 = Product(0, 0, 0, 0)
product2 = Product(0, 0, 0, 0)

product1.set_details()
product1.get_details()

product2.set_details()
product2.get_details()
52 changes: 52 additions & 0 deletions Society.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'''
Create the class Society with following information:
society_name, house_no, no_of_members, flat, income
Methods :
An __init__ method to assign initial values of society_name, flat, house_no, no_of_members, income
input_data() To read information from members
allocate_flat() To allocate flat according to income using the below table.
show_data() to display the details of the entire class.
Income Flat
>=25000 A Type
>=20000 and <25000 B Type
>=15000 and <20000 C Type
<15000 D Type
Author= Bulent Caliskan date= 08/02/2021
'''



class Society:
def __init__(self,society_name, flat, house_no, no_of_members, income):
self.society_name = society_name
self.flat = flat
self.house_no = house_no
self.no_of_members = no_of_members
self.income = income

def input_data(self):
self.society_name = input("Enter society name ? ")
self.house_no = input("Enter your house number ? ")
self.no_of_members = input("Enter how many members your house has ? ")
self.income = input("Enter your income ? ")

def allocate_flat(self):
if self.income >=25000:self.flat="A"
elif 20000<=self.income<25000:self.flat="B"
elif 15000<=self.income<20000:self.flat="C"
else:self.flat="D"

def show_data(self):
print(f"Your society name :{self.society_name}\
\nYour Flat type :{self.flat}\
\nYour house no :{self.house_no}\
\nYour house no of members:{self.no_of_members}\
\nYour income :{self.income}")

citizen1=Society("Dark Apt.","D",75,5,26000)
citizen2=Society("Blue Apt.","A",16,4,30000)

citizen1.input_data()
citizen1.show_data()
citizen2.input_data()
citizen2.show_data()