Commit 0d3aafab authored by Raquel's avatar Raquel 💬

week3/ day3

parent b8d8751c
......@@ -4,7 +4,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (venv)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.7" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TestRunnerService">
......
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (venv)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
This diff is collapsed.
.idea
.DS_Store
\ No newline at end of file
class Bookshelf:
def __init__(self, books):
self.books=books
self.book_storage = []
self.add_book()
#method to add books to bookshelf (book_storage)
def add_book(self):
for x,y in self.books:
self.book_storage.append(Book(x,y))
for book in self.book_storage:
print (book)
class Book:
def __init__(self,title,author):
self.title=title
self.author = author
def __str__(self):
return f"{self.title} by {self.author}"
#book1=Book("title1", "author1")
#print(book1)
book_shelf=Bookshelf(books=[('The old man and the see', 'Ernest Hemingway'),
('Beyond Good and Evil', 'Friedrich Nietzsche'),])
#print(book_shelf)
\ No newline at end of file
class Dish:
def __init__(self,name, price, ingredients):
self.name=name
self.price=price
self.ingredients = ingredients
def cost(self):
cost=10
for x in self.ingredients:
cost+=x.cost
return cost
def profit(self):
profit= self.price - self.cost()
return profit
def __str__(self):
return self.name
class Restaurant:
def __init__(self, order):
self.order=[]
def order_dish(self,dish):
self.order.append(dish)
def print_orders(self):
for dish in self.order:
return f" Order # {self.order.index(dish)} : {dish}"
def print_check(self):
total=0
for dish in self.order:
total += dish.price
return f" Order # {self.order.index(dish)} : {dish} - {dish.price} \n Total: {total}"
class Ingredients:
def __init__(self,name, cost):
self.name=name
self.cost=cost
cheese = Ingredients('Cheese', 5)
pepperoni = Ingredients('pepperoni', 5)
dough = Ingredients('dough', 5)
#salad = Dish('Salad')
#print(pizza.name)
pizza = Dish("Pizza", 35, [cheese, pepperoni, dough])
restaurant= Restaurant(pizza )
print(restaurant.order_dish(pizza))
restaurant.print_orders()
#restaurant.order_dish(salad)
#restaurant.print_orders()
#print(cheese.name)
#print(pizza.ingredients) #not printing out the ingredient array-why?
#print(pizza.cost())
#print(pizza.profit()) # => 8
print(restaurant.print_check())
class Dish:
def __init__(self,name, price, ingredients):
self.name=name
self.price=price
self.ingredients = ingredients
def cost(self):
cost=10
for x in self.ingredients:
cost+=x.cost
return cost
def profit(self):
profit= self.price - self.cost()
return profit
def __str__(self):
return self.name
class Restaurant:
def __init__(self):
self.order=[]
def order_dish(self,client,dish):
self.order.append([client,dish])
return self.order
def print_orders(self, client):
for order in self.order:
return f" Customer {client} \n Order # {self.order.index(order)} : {order[1]} - {order[1].price}"
def print_check(self,client):
total=0
# this code is just to assure the customer name will be printed only once
if len(list(zip(*self.order))[0]) > 0: #zip retrieves the first element accross a lists and returns a list with them
print(f" Customer {client} \n ")
#end
for order in self.order:
if order[0] == client:
total += order[1].price
print( f" Order # {self.order.index(order)} : {order[1]} - {order[1].price}")
print(f" Total: {total}")
class Ingredients:
def __init__(self,name, cost):
self.name=name
self.cost=cost
cheese = Ingredients('Cheese', 5)
pepperoni = Ingredients('pepperoni', 5)
dough = Ingredients('dough', 5)
pizza = Dish("Pizza", 35, [cheese, pepperoni, dough])
salad = Dish("salad", 35, [cheese, pepperoni, dough])
restaurant= Restaurant()
restaurant.order_dish("Goofy", pizza)
restaurant.order_dish("Goofy", salad)
#print(restaurant.print_orders("Goofy"))
restaurant.print_check("Goofy")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment