Skip to content
Snippets Groups Projects
Commit 8180026b authored by Daniel Moix's avatar Daniel Moix
Browse files

Adding Lecture 6

parent ddf2f00a
Branches
No related tags found
No related merge requests found
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
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))
from scope import doSomething
doSomething("Something")
\ No newline at end of file
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
def doSomething(text, endChar=''):
print(text.upper() + endChar)
print(value)
if __name__ == '__main__':
value = 10
doSomething("hello", '!')
print(value)
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)
from queue import PriorityQueue
pq = PriorityQueue()
pq.put((1, "One"))
pq.put((10, "Ten"))
print(pq.get())
\ No newline at end of file
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
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)
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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment