From 8180026b02b5c2f784f8419b0860e822d8079689 Mon Sep 17 00:00:00 2001 From: Daniel Moix <dwm69@drexel.edu> Date: Tue, 8 Aug 2023 17:10:21 -0400 Subject: [PATCH] Adding Lecture 6 --- cs171/Lect06/counting.py | 23 +++++++++++++++++++++++ cs171/Lect06/hello.py | 33 +++++++++++++++++++++++++++++++++ cs171/Lect06/import.py | 3 +++ cs171/Lect06/nested.py | 9 +++++++++ cs171/Lect06/scope.py | 10 ++++++++++ cs171/Lect06/swap.py | 23 +++++++++++++++++++++++ cs172/Lect06/PQ.py | 8 ++++++++ cs172/Lect06/hello.py | 15 +++++++++++++++ cs172/Lect06/myqueue.py | 33 +++++++++++++++++++++++++++++++++ cs172/Lect06/mystack.py | 32 ++++++++++++++++++++++++++++++++ 10 files changed, 189 insertions(+) create mode 100644 cs171/Lect06/counting.py create mode 100644 cs171/Lect06/hello.py create mode 100644 cs171/Lect06/import.py create mode 100644 cs171/Lect06/nested.py create mode 100644 cs171/Lect06/scope.py create mode 100644 cs171/Lect06/swap.py create mode 100644 cs172/Lect06/PQ.py create mode 100644 cs172/Lect06/hello.py create mode 100644 cs172/Lect06/myqueue.py create mode 100644 cs172/Lect06/mystack.py diff --git a/cs171/Lect06/counting.py b/cs171/Lect06/counting.py new file mode 100644 index 0000000..2eab323 --- /dev/null +++ b/cs171/Lect06/counting.py @@ -0,0 +1,23 @@ + + +def countUp(low, high, step=1): + while low <= high: + print(low) + low += step + +def countDown(high, low=1, step=1): + ''' Good place to define step to be a non-negative int''' + while high >= low: + print(high) + high -= step + + +# countUp(1, 10) +countUp(10, 100, 10) + +#countDown(50, 25, 5) +#countDown(int(input("Count down from what: "))) + +myText = "I like the Drexel Dragon, whose name is Mario" +myWords = myText.split() +print(myWords) \ No newline at end of file diff --git a/cs171/Lect06/hello.py b/cs171/Lect06/hello.py new file mode 100644 index 0000000..97bca48 --- /dev/null +++ b/cs171/Lect06/hello.py @@ -0,0 +1,33 @@ +print("hello again") + +def golfWinner(left, right): + print("We have two bad golfers...") + if left < right: + return "Left" + else: + return "Right" + print("Thank you for playing") + +def golf(left=0, right=0): + if left < right: + print("Left wins") + else: + print("Right wins") + +def sum(left, right): + return left + right + + + #Parameter +def sayHello(dayName): # Begin Definition + print("It is a ", dayName) + print("This is your lecture") + print("microphone") + print("Oh, and hello") # End Definition + + #Argument +todayIs = "Monday" +sayHello("Tuesday") # Call Function + +print(golfWinner(100, 200)) + diff --git a/cs171/Lect06/import.py b/cs171/Lect06/import.py new file mode 100644 index 0000000..e4add00 --- /dev/null +++ b/cs171/Lect06/import.py @@ -0,0 +1,3 @@ +from scope import doSomething + +doSomething("Something") \ No newline at end of file diff --git a/cs171/Lect06/nested.py b/cs171/Lect06/nested.py new file mode 100644 index 0000000..f2e1abb --- /dev/null +++ b/cs171/Lect06/nested.py @@ -0,0 +1,9 @@ + + +def sum(a, b): + return a + b + +def mul(a, b): + return a * b + +print(sum(mul(18, sum(3, 0)), sum(mul(2, 2), 4))) \ No newline at end of file diff --git a/cs171/Lect06/scope.py b/cs171/Lect06/scope.py new file mode 100644 index 0000000..360e003 --- /dev/null +++ b/cs171/Lect06/scope.py @@ -0,0 +1,10 @@ + + +def doSomething(text, endChar=''): + print(text.upper() + endChar) + print(value) + +if __name__ == '__main__': + value = 10 + doSomething("hello", '!') + print(value) diff --git a/cs171/Lect06/swap.py b/cs171/Lect06/swap.py new file mode 100644 index 0000000..d5478f6 --- /dev/null +++ b/cs171/Lect06/swap.py @@ -0,0 +1,23 @@ + + +def family(): + ''' Returns a tuple of family member ''' + return ("Mother", "Father", "Brother") + +def swap(myList): + temp = myList[1] + myList[1] = myList[0] + myList[0] = temp + return myList + +def lazySwap(yourList): + ''' Exchanges the values in the first two positions of the list''' + yourList[0], yourList[1] = yourList[1], yourList[0] + +member1, member2, member3 = family() + +print(swap(["Red", "Green"])) + +theirList = ["Philadelphia", "Pennsylvania"] +lazySwap(theirList) +print(theirList) diff --git a/cs172/Lect06/PQ.py b/cs172/Lect06/PQ.py new file mode 100644 index 0000000..3846b88 --- /dev/null +++ b/cs172/Lect06/PQ.py @@ -0,0 +1,8 @@ +from queue import PriorityQueue + +pq = PriorityQueue() + +pq.put((1, "One")) +pq.put((10, "Ten")) + +print(pq.get()) \ No newline at end of file diff --git a/cs172/Lect06/hello.py b/cs172/Lect06/hello.py new file mode 100644 index 0000000..da9eacc --- /dev/null +++ b/cs172/Lect06/hello.py @@ -0,0 +1,15 @@ +from queue import Queue, LifoQueue + +myQueue = Queue() +myStack = LifoQueue() + +myQueue.put(5) +myQueue.put(10) + +myStack.put(5) +myStack.put(10) + +while not myStack.empty(): + print(myStack.get()) + +#print(myQueue) \ No newline at end of file diff --git a/cs172/Lect06/myqueue.py b/cs172/Lect06/myqueue.py new file mode 100644 index 0000000..fdfbba8 --- /dev/null +++ b/cs172/Lect06/myqueue.py @@ -0,0 +1,33 @@ +class myQueue: + + def __init__(self): + self.__contents = [] + + def get(self): + return self.__contents.pop(0) + + def put(self, thing): + self.__contents.append(thing) + + def empty(self): + return len(self.__contents) == 0 + + def clear(self): + self.__contents = [] + + def __str__(self): + return str(self.__contents) + +if __name__ == "__main__": + testQueue = myQueue() + testQueue.put(5) + testQueue.put(10) + + # testQueue.clear() + + print(testQueue) + print(testQueue.empty()) + + print(testQueue.get()) + print(testQueue) + diff --git a/cs172/Lect06/mystack.py b/cs172/Lect06/mystack.py new file mode 100644 index 0000000..4ffb7fb --- /dev/null +++ b/cs172/Lect06/mystack.py @@ -0,0 +1,32 @@ +class MyStack: + + def __init__(self): + self.__contents = [] + + def get(self): + return self.__contents.pop() + + def put(self, thing): + self.__contents.append(thing) + + def empty(self): + return len(self.__contents) == 0 + + def clear(self): + self.__contents = [] + + def __str__(self): + return str(self.__contents) + +if __name__ == "__main__": + testStack = MyStack() + testStack.put(5) + testStack.put(10) + + # testStack.clear() + + print(testStack) + print(testStack.empty()) + + print(testStack.get()) + print(testStack) -- GitLab