From e6d76a9201ad7b40c1aa358f25455d5ddb951c39 Mon Sep 17 00:00:00 2001 From: cabirerguven <77165060+cabirerguven@users.noreply.github.com> Date: Wed, 10 Feb 2021 21:17:28 +0100 Subject: [PATCH] Week 5 --- W5_Q1_class_Society.py | 62 ++++++++++++++++++++++++++++++ W5_Q2_Item_Info.py | 52 +++++++++++++++++++++++++ W5_Q3_Product.py | 49 ++++++++++++++++++++++++ W5_Q4_Customer_Item.py | 86 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 249 insertions(+) create mode 100644 W5_Q1_class_Society.py create mode 100644 W5_Q2_Item_Info.py create mode 100644 W5_Q3_Product.py create mode 100644 W5_Q4_Customer_Item.py diff --git a/W5_Q1_class_Society.py b/W5_Q1_class_Society.py new file mode 100644 index 0000000..47281bb --- /dev/null +++ b/W5_Q1_class_Society.py @@ -0,0 +1,62 @@ +# 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 + +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.flat = input("Enter flat number: ") + self.house_no = input("Enter House No: ") + self.no_of_members = input("Enter No of Members: ") + self.income = int(input("Enter income: ")) + + def allocate_flat(self): + if self.income >= 25000: + self.flattype ="A Type" + elif self.income >= 20000: + self.flatype = "B Type" + elif self.income >= 15000: + self.flattype = "C Type" + else: + self.flattype = "D Type" + + def show_data(self): + return f"Society name: {self.society_name} \tFlat Number: {self.flat}\tHouse number: {self.house_no} " \ + f"\tNo of members: {self.no_of_members} \tFlat type: {self.flattype} \tIncome: {self.income}" + + +person1 = Society("",0,0,0,0) +person2 = Society("",0,0,0,0) +person3 = Society("",0,0,0,0) + + +person1.input_data() +person2.input_data() +person3.input_data() + +person1.allocate_flat() +person2.allocate_flat() +person3.allocate_flat() + +print(" SUMMARY ".center(100,"-")) +print(person1.show_data()) +print(person2.show_data()) +print(person3.show_data()) + + diff --git a/W5_Q2_Item_Info.py b/W5_Q2_Item_Info.py new file mode 100644 index 0000000..86265db --- /dev/null +++ b/W5_Q2_Item_Info.py @@ -0,0 +1,52 @@ +# 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, item_code=0, price=0, qty=0, net_price=0, discount=0): + self.item_code = item_code + self.price = price + self.qty = qty + self.net_price = net_price + self.discount = discount + + def Buy(self): + self.item_code = input("Urun Kodunu Giriniz: ") + self.item = input("Urun Adini Giriniz: ") + self.price = int(input("Urun Fiyatini Giriniz: ")) + self.qty = int(input("Urun Miktarini Giriniz: ")) + self.discount = self.CalculateDiscount() + self.net_price = self.qty * (self.price - (self.price * self.discount / 100)) + + def CalculateDiscount(self): + if self.qty <= 10: + self.discount = 0 + elif self.qty <=20: + self.discount = 15 + else: + self.discount = 20 + return self.discount + + def ShowData(self,x): + print(" Siparis Ozeti ".center(100,"-")) + print(f"\nUrun Kodu: {item1.item_code} \nUrun Adi:{item1.item}\nUrun Fiyati: {item1.price} " + f"\nUrun Miktari: {item1.qty} \nIndirimden Onceki Fiyat: {item1.qty*item1.price}" + f"\nIndirimli Fiyat: {item1.net_price}") + +item1 = ItemInfo() + +(item1.ShowData(item1.Buy())) + diff --git a/W5_Q3_Product.py b/W5_Q3_Product.py new file mode 100644 index 0000000..09a0912 --- /dev/null +++ b/W5_Q3_Product.py @@ -0,0 +1,49 @@ +# 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. + +# +# 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 : + + +class Product(): + def __init__(self, p_id, p_name, p_purchase_price, p_sale_price ): + self.p_id = p_id + self.p_name = p_name + self.p_purchase_price = p_purchase_price + self.p_sale_price = p_sale_price + + def set_remarks(self): + if self.p_sale_price - self.p_purchase_price > 0: + return "Profit" + else: + return "Loss" + + def set_details(self): + self.p_id = input("Enter Product ID: ") + self.p_name = input("Enter Product Name: ") + self.p_purchase_price = int(input("Enter Product Purchase Price: ")) + self.p_sale_price = int(input("Enter Product Sale Price: ")) + self.set_remarks() + + + def get_details(self,x): + print(" Product Summary ".center(100, "-")) + print(f"\nProduct ID: {product1.p_id} \nProduct Name:{product1.p_name}\nProduct Purchase Price:" + f" {product1.p_purchase_price} \nProduct Sale Price: {product1.p_sale_price} \nProduct Remarks:" + f" {product1.set_remarks() }") + +product1 = Product(0,"" ,0 , 0) + +product1.get_details(product1.set_details()) \ No newline at end of file diff --git a/W5_Q4_Customer_Item.py b/W5_Q4_Customer_Item.py new file mode 100644 index 0000000..00345c7 --- /dev/null +++ b/W5_Q4_Customer_Item.py @@ -0,0 +1,86 @@ +# 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 Items: + def __init__(self, cust_id=0 , price=0, total_price=0, qty=0,discount=0,items=0 ): + self.cust_id= cust_id + self.total_price = total_price + self.price = price + self.items = items + self.qty = qty + self.discount = discount + + def __str__(self): + self.shopping_cart_list = [] + print(" Product Summary ".center(100, "-")) + return (f"\nProduct Name: {self.items} \nProduct Price: {self.price}\nProduct Amount: {self.qty}" + f"\nTotal Discount: {self.discount}\nTotal Payment after discount: {self.price_tobe_paid}") + + def calculate_discount(self): + self.total_price = self.price * self.qty + if self.total_price < 2000: + self.discount = self.total_price * 0.1 + + if self.total_price <= 4000: + self.discount = self.total_price * 0.15 + + if self.total_price > 4000: + self.discount = self.total_price * 0.25 + + def shopping_cart(self,x): + self.items = input("Product to add shopping Basket: ") + self.price = int(input("Enter the price of Product: ")) + self.qty = int(input("How many do you want to buy? ")) + self.calculate_discount() + self.get_total_amount() + + def get_total_amount(self): + self.price_tobe_paid = self.total_price - self.discount + return self.price_tobe_paid + +class Customer: + + def __init__(self, name, surname, age, phone, cust_id, qty): + self.name = name + self.qty = qty + self.surname = surname + self.age = age + self.phone = phone + self.cust_id = cust_id + + def get_cust_info(self): + self.name = input("Enter your name: ") + self.surname = input("Enter your surname: ") + self.age = int(input("Enter your age: ")) + self.phone = input("Enter your phone number: ") + + def __str__(self): + print(" Customer Summary ".center(100, "-")) + return(f"\nCustomer Name: {self.name} \nCustomer Surname: {self.surname}\n" + f"Customer Age: {self.age} \nCustomer Phone: {self.phone}") + +customer1 = Customer(0,"",0 ,0 ,0 ,0) +customer1.get_cust_info() + +product1 = Items() +product1.shopping_cart(customer1.cust_id) + +print(customer1) +print(product1)