...
 
Commits (5)
......@@ -53,7 +53,7 @@ class Restaurant {
sum += this.orders[client.id][i].price
console.log("Order # " + i + " : " + this.orders[client.id][i].dish + "-" +
this.orders[client.id][i].price) //why can i call price here, if price is in a different class
this.orders[client.id][i].price)
=======
for (let i = 0; i < this.orders[client.id].length; i++) {
sum += this.orders[client.id][i].price
......
......@@ -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
/build/
/dist/
.egg-info
"""
BEFORE THE INIT FILE WAS CREATED:
from my_joke.joke import funny_joke
from my_joke.dark_joke import dark_joke
print (funny_joke())
print (dark_joke())
"""
import my_joke
#package.function
print (my_joke.funny_joke())
print (my_joke.dark_joke())
\ No newline at end of file
import sorting_algorithms_Raquelcodess
#to test if package __init__works
print (sorting_algorithms_Raquelcodess.bubbleSort([1, 2, 3, ]))
print (sorting_algorithms_Raquelcodess.selectionSort([1, 2, 3, ]))
print (sorting_algorithms_Raquelcodess.insertionSort([1, 2, 3, ]))
print (sorting_algorithms_Raquelcodess.quick_sort([4, 1, 2, 3, ]))
from .joke import funny_joke
from .dark_joke import dark_joke
from .dark_joke import * #this will import all the functions in the file
from .dark_joke import function1, function2 #this will import only these specific functions in the file
def dark_joke():
return "bla bla joke"
\ No newline at end of file
def funny_joke():
return "bla bla joke"
import pyjokes
# we can et up cirtual envoronments
#we can set up a VM witha requrements file
print(pyjokes.get_joke())
name: day4
dependencies:
- python==3.7
- pip:
- twine
- flake8
- nose
\ No newline at end of file
from setuptools import setup
setup(name='sorting_algorithms_v3',
version='0.1',
description='sorting algorithms in python3',
url='https://gitlab.propulsion-home.ch/',
author='Raquelcodes',
author_email='Raquelcodes@example.com',
license='MIT',
packages=['sorting_algorithms_v3'],
test_suite='nose.collector',
tests_require=['nose'],
zip_safe=False)
\ No newline at end of file
def bubbleSort(alist):
for passnum in range(len(alist) - 1, 0, -1):
for i in range(passnum):
if alist[i] > alist[i + 1]:
temp = alist[i]
alist[i] = alist[i + 1]
alist[i + 1] = temp
return alist
def insertionSort(alist):
for index in range(1, len(alist)):
currentvalue = alist[index]
position = index
while position-1 >= 0 and alist[position-1] > currentvalue:
alist[position] = alist[position-1]
position = position - 1
alist[position] = currentvalue
return alist
def quick_sort(alist):
quick_sort_helper(alist, 0, len(alist) - 1)
return alist
def quick_sort_helper(alist, first, last):
if first < last:
splitpoint = partition(alist, first, last)
quick_sort_helper(alist, first, splitpoint - 1)
quick_sort_helper(alist, splitpoint + 1, last)
def partition(alist, first, last):
pivotvalue = alist[first]
leftmark = first + 1
rightmark = last
done = False
while not done:
while leftmark <= rightmark and alist[leftmark] <= pivotvalue:
leftmark = leftmark + 1
while alist[rightmark] >= pivotvalue and rightmark >= leftmark:
rightmark = rightmark - 1
if rightmark < leftmark:
done = True
else:
temp = alist[leftmark]
alist[leftmark] = alist[rightmark]
alist[rightmark] = temp
temp = alist[first]
alist[first] = alist[rightmark]
alist[rightmark] = temp
return rightmark
This package has several sorting algorithms in python3.
ENJOY!
\ No newline at end of file
def selectionSort(alist):
for fillslot in range(len(alist) - 1, 0, -1):
positionOfMax = 0
for location in range(1, fillslot + 1):
if alist[location] > alist[positionOfMax]:
positionOfMax = location
temp = alist[fillslot]
alist[fillslot] = alist[positionOfMax]
alist[positionOfMax] = temp
return alist
from .Bubble_Sort import *
from .Insertion_Sort import *
from .Quick_Sort import *
from .Selection_Sort import *
from .tests import *
\ No newline at end of file
import unittest
from unittest import TestCase
import sorting_algorithms_v3
class TestSorting1(TestCase):
def test_is_Sorted(self):
s = [1,4,3,2]
t = sorting_algorithms_v3.bubbleSort(s)
self.assertEqual(t, [1,2,3,4])
class TestSorting2(TestCase):
def test_is_Sorted(self):
s = [1, 4, 3, 2]
self.assertEqual(sorting_algorithms_v3.selectionSort(s), [1, 2, 3, 4])
class TestSorting3(TestCase):
def test_is_Sorted(self):
s = [1, 4, 3, 2]
self.assertEqual(sorting_algorithms_v3.insertionSort(s), [1, 2, 3, 4])
class TestSorting4(TestCase):
def test_is_Sorted(self):
s = [1, 4, 3, 2]
self.assertEqual(sorting_algorithms_v3.quick_sort(s), [1, 2, 3, 4])
if __name__ == '__main__':
unittest.main()
.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")
.idea
.DS_Store
\ No newline at end of file