diff --git a/cs171/Lect06/counting.py b/cs171/Lect06/counting.py new file mode 100644 index 0000000000000000000000000000000000000000..2eab323d2f69dcee20b03b57131c2b576b399842 --- /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 0000000000000000000000000000000000000000..97bca488f83b90d75bb7a5384de809d8ca1fdc83 --- /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 0000000000000000000000000000000000000000..e4add0067e5bc5f87085d57c8a46d4f0895ac6d2 --- /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 0000000000000000000000000000000000000000..f2e1abb463d78d41ce51252c5f6b7a4a911e91b2 --- /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 0000000000000000000000000000000000000000..360e0036ff94ca03542a306b64a2dc76e0c00e7f --- /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 0000000000000000000000000000000000000000..d5478f6e56e1d18be3d5fe3f9d5cbb146904ab63 --- /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 0000000000000000000000000000000000000000..3846b888299290853155b6a13ff3e3c1c12e5e09 --- /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 0000000000000000000000000000000000000000..da9eaccc3d91b360535b6d7f3853661d25fc0e5f --- /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 0000000000000000000000000000000000000000..fdfbba8063b30aa980bb16cc4a46f0329e2e03f0 --- /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 0000000000000000000000000000000000000000..4ffb7fbcffa08b64159b533eb2f228b813ea0be7 --- /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)