From 5f6b23cdd1246ef4d5eb9cb803b5f008a59747d3 Mon Sep 17 00:00:00 2001 From: Daniel Moix <dwm69@drexel.edu> Date: Tue, 27 Jun 2023 17:50:24 -0400 Subject: [PATCH] Adding CS 172 Lecture 1 files --- cs172/Lect01/broken_demo.py | 9 ++++++++ cs172/Lect01/module.py | 9 ++++++++ cs172/Lect01/notModule.py | 9 ++++++++ cs172/Lect01/pringle.py | 41 +++++++++++++++++++++++++++++++++++++ cs172/Lect01/script.py | 2 ++ 5 files changed, 70 insertions(+) create mode 100644 cs172/Lect01/broken_demo.py create mode 100644 cs172/Lect01/module.py create mode 100644 cs172/Lect01/notModule.py create mode 100644 cs172/Lect01/pringle.py create mode 100644 cs172/Lect01/script.py diff --git a/cs172/Lect01/broken_demo.py b/cs172/Lect01/broken_demo.py new file mode 100644 index 0000000..49f6553 --- /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 0000000..3a1b176 --- /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 0000000..3a1b176 --- /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 0000000..888470a --- /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 0000000..2640f21 --- /dev/null +++ b/cs172/Lect01/script.py @@ -0,0 +1,2 @@ +print("Hello") +print("Goodbye") \ No newline at end of file -- GitLab