diff --git a/cs172/Lect01/broken_demo.py b/cs172/Lect01/broken_demo.py new file mode 100644 index 0000000000000000000000000000000000000000..49f6553338540a713b46fb11b44790fbd98b8835 --- /dev/null +++ b/cs172/Lect01/broken_demo.py @@ -0,0 +1,9 @@ +import notModule +print(notModule.larger(11, 22)) + + +# from notModule import sum +# print(sum(11, 22)) + +# from notModule import sum, larger +# print(sum(11, 22)) \ No newline at end of file diff --git a/cs172/Lect01/module.py b/cs172/Lect01/module.py new file mode 100644 index 0000000000000000000000000000000000000000..3a1b176016c0f8be269caf7a62fcfa4d7357a57f --- /dev/null +++ b/cs172/Lect01/module.py @@ -0,0 +1,9 @@ +def sum(num1, num2): + return num1+num2 + +def larger(num1, num2): + if num1 > num2: + return num1 + else: + return num2 + \ No newline at end of file diff --git a/cs172/Lect01/notModule.py b/cs172/Lect01/notModule.py new file mode 100644 index 0000000000000000000000000000000000000000..3a1b176016c0f8be269caf7a62fcfa4d7357a57f --- /dev/null +++ b/cs172/Lect01/notModule.py @@ -0,0 +1,9 @@ +def sum(num1, num2): + return num1+num2 + +def larger(num1, num2): + if num1 > num2: + return num1 + else: + return num2 + \ No newline at end of file diff --git a/cs172/Lect01/pringle.py b/cs172/Lect01/pringle.py new file mode 100644 index 0000000000000000000000000000000000000000..888470afd329d9cf1fe6af01dba0379839ceb537 --- /dev/null +++ b/cs172/Lect01/pringle.py @@ -0,0 +1,41 @@ +# Program: Simulate a Pringle Can + +class can: + #Constructor + def __init__(self, flavor): + self.__isOpen = False + self.__numChips = 50 + self.__flavor = flavor + + def eat(self): + if self.__isOpen and self.__numChips > 0: + self.__numChips -= 1 + + def open(self): + self.__isOpen = True + + def close(self): + self.__isOpen = False + + def getChips(self): + return self.__numChips + + def isEmpty(self): + return self.__numChips == 0 + + def __str__(self): + return "A " + self.__flavor +" Pringle Can containing " \ + + str(self.__numChips) + " chips." + + # Attributes: number of chips, flavor, open or not + +myCan = can("BBQ") #Create a new, full, closed can +myCan.open() +while not myCan.isEmpty(): + myCan.eat() + print("Mmm") +myCan.close() + +print(myCan.getChips()) +print(myCan) + diff --git a/cs172/Lect01/script.py b/cs172/Lect01/script.py new file mode 100644 index 0000000000000000000000000000000000000000..2640f21818226f9c18d6ce69681e30c57232a0f4 --- /dev/null +++ b/cs172/Lect01/script.py @@ -0,0 +1,2 @@ +print("Hello") +print("Goodbye") \ No newline at end of file