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
57 changes: 57 additions & 0 deletions 1- Society Kerim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Question 1:
# 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.

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

def input_data(self):
""" Reads information from members """
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= int(input("Enter income: "))


def allocate_flat(self):
""" Allocates flat according to income using the below table. """
if self.income >= 25_000:
self.flat = "A Type"
elif 20_000 <= self.income < 25_000:
self.flat = "B Type"
elif 15_000 <= self.income < 20_000:
self.flat = "C Type"
elif self.income < 15_000:
self.flat = "D Type"


def show_data(self):
""" Displays the details of the entire class. """
return f"Society name: {self.society_name} \tHouse number: {self.house_no} \tNo of members: {self.no_of_members} \tFlat type: {self.flat} \tIncome: {self.income}"

s1 = Society("Top Apartments", "A type", 36, 4, 26_000) # Member S1
s2 = Society("Best Apartments", "C type", 24, 9, 21_000) # Changes Flat type as "B type"
s3 = Society("Poor Apartments", "B type", 12, 16, 6_000) # Changes Flat type as "D type"
#s1.input_data()
#s2.input_data()
#s2.input_data()
s1.allocate_flat()
s2.allocate_flat()
s3.allocate_flat()
print(s1.show_data())
print(s2.show_data())
print(s3.show_data())

71 changes: 71 additions & 0 deletions 2- ItemInfo Kerim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Question 2:
# 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.


class ItemInfo:

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

def calculate_Discount(self):
""" Calculates 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 """

if self.qty <= 10:
self.discount = 0
if 11 <= self.qty <= 20:
self.discount = 15
if self.qty > 20:
self.discount = 20
return self.discount

def buy(self):
""" Allows user to enter values for item_code, item, price, qty"""
self.item_code = input("Enter item code: ")
self.item = input("Enter the item: ")
self.price = float(input(f"Enter the price of the {self.item}: "))
self.qty = int(input(f"Enter the quantity of the {self.item}: "))
self.discount = self.calculate_Discount() # Calls function calculate_discount()
self.net_price = (self.qty * (self.price - (self.price*(self.discount/100)))) # Calculates Discount with Procent

def showAll(self):
""" Allows user to view the content of all the data members. """
all_result = """
Item code: {}
Item name: {}
Item price: {}
Item quantity: {}
Item Discount: {} procent
Item Price after discount: {}
""".format(self.item_code,self.item,self.price,self.qty, self.discount, self.net_price)
return all_result

my_item1 = ItemInfo()
my_item1.buy()
print(my_item1.showAll())

my_item2 = ItemInfo()
my_item2.buy()
print(my_item2.showAll())

my_item3 = ItemInfo()
my_item3.buy()
print(my_item3.showAll())
58 changes: 58 additions & 0 deletions 3- Product Kerim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 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 :
# image

# 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.

class Product:
def __init__(self, product_id,product_name, product_purchase_price, product_sale_price):
self.product_id = str(product_id)
self.product_name = str(product_name)
self.product_purchase_price = float(product_purchase_price)
self.product_sale_price = float(product_sale_price)

def set_remarks(self):
""" Stores "Profit" if Margin is positive else "Loss" if Margin is negative. """
self.price_margin = self.product_sale_price - self.product_purchase_price
if self.price_margin < 0:
return "Loss"
elif self.price_margin > 0:
return "Profit"

def set_details(self):
""" Accepts values for product_id. product_name, product_purchase_price, product_sale_price and invokes SetRemarks() method. """
self.product_id = str(input("Enter product id: "))
self.product_name = str(input("Enter product name: "))
self.product_purchase_price = float(input("Enter product purchase price: "))
self.product_sale_price = float(input("Enter product sale price: "))
self.product_margin = self.set_remarks()

def get_details(self):
""" Displays all the data members. """

all_result = """
Product id: {}
Product name: {}
Product purchase price: {}
Product sale price: {}
Product margin: {}
""".format(self.product_id,self.product_name,self.product_purchase_price,self.product_sale_price, self.product_margin)
return all_result


p = Product(1894, "Laptop", 100, 120)
p.set_details()
p.set_remarks()
print(p.get_details())
110 changes: 110 additions & 0 deletions 4- Customer - Items Kerim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Question 4:
# 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]

# Crate a few customers and print their information (Personal and shopping info).

class Items:
def __init__(self,price=0,qty=0):
self.price = price
self.qty = qty

def __str__(self):
all_result = """
Customer id: {}, Item name: {}, Item price: {}, Item quantity: {}, Total price: {}, Total discount {} procent, To be paid after discount: {}
""".format(self.customer_id,self.item_name, self.price, self.qty, self.total_price,self.discount, self.price_to_be_paid)
return all_result

def calculate_discount(self):
self.total_price = self.price * self.qty
if self.total_price >= 4000:
self.discount = 25
elif 2000 <= self.total_price < 4000:
self.discount = 15
elif self.total_price < 2000:
self.discount = 10

def shopping_cart(self):
""" Users can add new items here """
self.customer_id = int(input("Enter your customer id: "))
self.item_name = input("Enter item name: ")
self.price = int(input(f"Enter price of {self.item_name}: "))
self.qty = int(input(f"Enter quantity of {self.item_name}: "))
self.calculate_discount()
self.get_total_amount()

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

class Customer:
def __init__(self, customer_id, name, surname):
self.customer_id = customer_id
self.name = name
self.surname = surname

def __str__(self):
return f"Customer name: {self.name}, Surname: {self.surname}, Customer id: {self.customer_id}"

def get_customer_info(self):
self.name = input("Enter your name: ")
self.surname = input("Enter your surname: ")
self.customer_id = int(input("Enter your customer id: "))

def merge(ob1,ob2):
result = """
{}
{}
""".format(ob1,ob2)
return result

my_customer1 = Customer(120,"Kerim","Sak")
my_customer1.get_customer_info()

my_item1 = Items()
my_item1.shopping_cart()

my_customer2 = Customer(100,"Ahmet","Uzunoglu")
my_customer2.get_customer_info()

my_item2 = Items()
my_item2.shopping_cart()

inst_1 = merge(my_customer1, my_item1)
print(inst_1)

inst_2 = merge(my_customer2, my_item2)
print(inst_2)