From 7b183b5232402762fd7f1c99d202901399b1dab1 Mon Sep 17 00:00:00 2001 From: caliskanbulent <55192161+caliskanbulent@users.noreply.github.com> Date: Tue, 9 Feb 2021 00:22:42 +0100 Subject: [PATCH 1/3] week5 --- CustomerItems.py | 93 +++++++++++++++++++++++++++++++++++++++++ ItemInfo.py | 57 +++++++++++++++++++++++++ Product.py | 60 +++++++++++++++++++++++++++ Society.py | 52 +++++++++++++++++++++++ TicTakToe.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 367 insertions(+) create mode 100644 CustomerItems.py create mode 100644 ItemInfo.py create mode 100644 Product.py create mode 100644 Society.py create mode 100644 TicTakToe.py diff --git a/CustomerItems.py b/CustomerItems.py new file mode 100644 index 0000000..fa9fb2d --- /dev/null +++ b/CustomerItems.py @@ -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__() diff --git a/ItemInfo.py b/ItemInfo.py new file mode 100644 index 0000000..459fe12 --- /dev/null +++ b/ItemInfo.py @@ -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 110 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() \ No newline at end of file diff --git a/Society.py b/Society.py new file mode 100644 index 0000000..8ed1b45 --- /dev/null +++ b/Society.py @@ -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() \ No newline at end of file diff --git a/TicTakToe.py b/TicTakToe.py new file mode 100644 index 0000000..85d6224 --- /dev/null +++ b/TicTakToe.py @@ -0,0 +1,105 @@ +''' +RULES FOR TIC-TAC-TOE. +The game is played on a grid that's 3 squares by 3 squares. +You are X, your friend is O. +The first player to get 3 of her marks in a row (up, down, across, or diagonally) is the winner. +When all 9 squares are full, the game is over. +Author= Bulent Caliskan date= 08/02/2021 +''' + +class TicTacToe: + #init functionda 2 oyuncunun isimlerini alip ve oyun panelini ve + # kazanmak icin hangi kosullarin olusmasi + #gerektigini yazioruz.hamle sayisini da 0 yapiyoruz. + def __init__(self,player1,player2): + self.player1 = input("Enter your name player 1? ") + self.player2 = input("Enter your name player 2? ") + self.panel = [1, 2, 3, 4, 5, 6, 7, 8, 9] + self.conditions = ((1, 2, 3), (4, 5, 6), (7, 8, 9), (1, 5, 9), (3, 5, 7), (1, 4, 7), (2, 5, 8), (3, 6, 9)) + self.moves = 0 + + #Paneli print yapiyoruz + def createPanel(self): + print(self.panel[0], self.panel[1], self.panel[2]) + print(self.panel[3], self.panel[4], self.panel[5]) + print(self.panel[6], self.panel[7], self.panel[8]) + + #oyuncu 1 in hangi numaraya X koymasini gerektigini soruyoruz. + #eger sectigi sayida bir isaret (X or O) yoksa isaretliyoruz. moves 1 arttiriyoruz. + # her seferinde check_win() ile kazandimi diye kontrol ediyoruz. + #yanli bir numara girerse 1 ole 9 arasinda gir diyoruz. + def gamer1(self): + try: + print(f"{self.player1}") + place = int(input("Which number would you like to mark {}? \n".format(self.player1))) + if self.panel[place-1] != "X" and self.panel[place-1] != "O": + self.panel[place-1] = "X" + self.createPanel() + self.moves += 1 + else: + print("The other player or you have already taken that row.") + self.gamer1() + self.check_win() + except : + print("WRITE A NUMBER FROM 1 TO 9") + self.gamer1() + #oyuncu 2 icinde oyuncu 1 ile ayni sartlari yaziyoruz. + def gamer2(self): + try: + + print(f"{self.player2}") + place = int(input("Which number would you like to mark {}? \n".format(self.player2))) + if self.panel[place-1] != "X" and self.panel[place-1] != "O": + self.panel[place-1] = "O" + self.createPanel() + self.moves += 1 + else: + print("The other player or you have already taken that row.") + self.gamer2() + self.check_win() + except: + print("WRITE A NUMBER FROM 1 TO 9") + self.gamer2() + + #play func.oyuncu 1 ile oyuncu 2 funclarini calistirir. + def play(self): + while True: + self.gamer1() + self.gamer2() + #Tekrar oynamak icin oyunculara donusu y/n olan soru soruyoruz. + #cevap y ise tekrar oaynatiyoruz n ise oyudan cikiyoruz. + def play_again(self): + while True: + question = input("Do you want to play again? Type y or n\n") + if question == "y": + self.panel = [1, 2, 3, 4, 5, 6, 7, 8, 9] + self.run() + elif question == "n": + print("See you next time!") + quit() + else: + print("Thats not a valid option") + + #Eger self.conditions daki kosullarin biri olusursa hangi oyuncu once tamamlarsa o kazanir. + #kazanan belli olduktan sonra tekrar oynamak istermisiniz diye soruyoruz. + # eger moves 9 olursa yani tum sayilar isaretlenmis olursa oyun biter. + def check_win(self): + for i in self.conditions: + if self.panel[i[0]-1] == self.panel[i[1]-1] == self.panel[i[2]-1] == "X": + print(f"{self.player1} WINS \nMOVES={self.moves}") + self.play_again() + if self.panel[i[0]-1] == self.panel[i[1]-1] == self.panel[i[2]-1] == "O": + print(f"{self.player2} WINS \nMOVES={self.moves}") + self.play_again() + elif self.moves == 9: + print("GAME OVER") + exit() + + #oyunun ilk baslangicini olusturmak icin run func kullaniyoruz. + def run(self): + self.createPanel() + self.play() + +#class i bir object e donuturup.run func. cagiriyoruz. +cos = TicTacToe("","") +cos.run() \ No newline at end of file From 2dfa592659031029e90e654bcd1ec5ec4034348a Mon Sep 17 00:00:00 2001 From: caliskanbulent <55192161+caliskanbulent@users.noreply.github.com> Date: Tue, 9 Feb 2021 00:25:47 +0100 Subject: [PATCH 2/3] Update TicTakToe.py --- TicTakToe.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TicTakToe.py b/TicTakToe.py index 85d6224..986a63e 100644 --- a/TicTakToe.py +++ b/TicTakToe.py @@ -21,8 +21,8 @@ def __init__(self,player1,player2): #Paneli print yapiyoruz def createPanel(self): print(self.panel[0], self.panel[1], self.panel[2]) - print(self.panel[3], self.panel[4], self.panel[5]) - print(self.panel[6], self.panel[7], self.panel[8]) + print(self.panel[3], self.panel[4], self.panel[5]) + print(self.panel[6], self.panel[7], self.panel[8]) #oyuncu 1 in hangi numaraya X koymasini gerektigini soruyoruz. #eger sectigi sayida bir isaret (X or O) yoksa isaretliyoruz. moves 1 arttiriyoruz. @@ -102,4 +102,4 @@ def run(self): #class i bir object e donuturup.run func. cagiriyoruz. cos = TicTacToe("","") -cos.run() \ No newline at end of file +cos.run() From 4aaf886ca8a2192ef396fca505cc36d034ddccfe Mon Sep 17 00:00:00 2001 From: caliskanbulent <55192161+caliskanbulent@users.noreply.github.com> Date: Tue, 9 Feb 2021 00:28:32 +0100 Subject: [PATCH 3/3] Delete TicTakToe.py --- TicTakToe.py | 105 --------------------------------------------------- 1 file changed, 105 deletions(-) delete mode 100644 TicTakToe.py diff --git a/TicTakToe.py b/TicTakToe.py deleted file mode 100644 index 986a63e..0000000 --- a/TicTakToe.py +++ /dev/null @@ -1,105 +0,0 @@ -''' -RULES FOR TIC-TAC-TOE. -The game is played on a grid that's 3 squares by 3 squares. -You are X, your friend is O. -The first player to get 3 of her marks in a row (up, down, across, or diagonally) is the winner. -When all 9 squares are full, the game is over. -Author= Bulent Caliskan date= 08/02/2021 -''' - -class TicTacToe: - #init functionda 2 oyuncunun isimlerini alip ve oyun panelini ve - # kazanmak icin hangi kosullarin olusmasi - #gerektigini yazioruz.hamle sayisini da 0 yapiyoruz. - def __init__(self,player1,player2): - self.player1 = input("Enter your name player 1? ") - self.player2 = input("Enter your name player 2? ") - self.panel = [1, 2, 3, 4, 5, 6, 7, 8, 9] - self.conditions = ((1, 2, 3), (4, 5, 6), (7, 8, 9), (1, 5, 9), (3, 5, 7), (1, 4, 7), (2, 5, 8), (3, 6, 9)) - self.moves = 0 - - #Paneli print yapiyoruz - def createPanel(self): - print(self.panel[0], self.panel[1], self.panel[2]) - print(self.panel[3], self.panel[4], self.panel[5]) - print(self.panel[6], self.panel[7], self.panel[8]) - - #oyuncu 1 in hangi numaraya X koymasini gerektigini soruyoruz. - #eger sectigi sayida bir isaret (X or O) yoksa isaretliyoruz. moves 1 arttiriyoruz. - # her seferinde check_win() ile kazandimi diye kontrol ediyoruz. - #yanli bir numara girerse 1 ole 9 arasinda gir diyoruz. - def gamer1(self): - try: - print(f"{self.player1}") - place = int(input("Which number would you like to mark {}? \n".format(self.player1))) - if self.panel[place-1] != "X" and self.panel[place-1] != "O": - self.panel[place-1] = "X" - self.createPanel() - self.moves += 1 - else: - print("The other player or you have already taken that row.") - self.gamer1() - self.check_win() - except : - print("WRITE A NUMBER FROM 1 TO 9") - self.gamer1() - #oyuncu 2 icinde oyuncu 1 ile ayni sartlari yaziyoruz. - def gamer2(self): - try: - - print(f"{self.player2}") - place = int(input("Which number would you like to mark {}? \n".format(self.player2))) - if self.panel[place-1] != "X" and self.panel[place-1] != "O": - self.panel[place-1] = "O" - self.createPanel() - self.moves += 1 - else: - print("The other player or you have already taken that row.") - self.gamer2() - self.check_win() - except: - print("WRITE A NUMBER FROM 1 TO 9") - self.gamer2() - - #play func.oyuncu 1 ile oyuncu 2 funclarini calistirir. - def play(self): - while True: - self.gamer1() - self.gamer2() - #Tekrar oynamak icin oyunculara donusu y/n olan soru soruyoruz. - #cevap y ise tekrar oaynatiyoruz n ise oyudan cikiyoruz. - def play_again(self): - while True: - question = input("Do you want to play again? Type y or n\n") - if question == "y": - self.panel = [1, 2, 3, 4, 5, 6, 7, 8, 9] - self.run() - elif question == "n": - print("See you next time!") - quit() - else: - print("Thats not a valid option") - - #Eger self.conditions daki kosullarin biri olusursa hangi oyuncu once tamamlarsa o kazanir. - #kazanan belli olduktan sonra tekrar oynamak istermisiniz diye soruyoruz. - # eger moves 9 olursa yani tum sayilar isaretlenmis olursa oyun biter. - def check_win(self): - for i in self.conditions: - if self.panel[i[0]-1] == self.panel[i[1]-1] == self.panel[i[2]-1] == "X": - print(f"{self.player1} WINS \nMOVES={self.moves}") - self.play_again() - if self.panel[i[0]-1] == self.panel[i[1]-1] == self.panel[i[2]-1] == "O": - print(f"{self.player2} WINS \nMOVES={self.moves}") - self.play_again() - elif self.moves == 9: - print("GAME OVER") - exit() - - #oyunun ilk baslangicini olusturmak icin run func kullaniyoruz. - def run(self): - self.createPanel() - self.play() - -#class i bir object e donuturup.run func. cagiriyoruz. -cos = TicTacToe("","") -cos.run()