diff options
author | standenboy <standenboy@StandenboyLAP.lan> | 2024-02-07 13:25:38 +0000 |
---|---|---|
committer | standenboy <standenboy@StandenboyLAP.lan> | 2024-02-07 13:25:38 +0000 |
commit | e4864bf1cd9e192eb54e492aaf02a397e143539c (patch) | |
tree | bed018816cb704e53839b1122081de799a6e5e8e /comp/work | |
parent | 073f1ce23d470bd85b0eb7497308f879ee214a48 (diff) |
added homework
Diffstat (limited to 'comp/work')
-rw-r--r-- | comp/work/22/classes.py | 20 | ||||
-rw-r--r-- | comp/work/23/higherorder.py | 10 | ||||
-rw-r--r-- | comp/work/23/recursion.py | 7 | ||||
-rw-r--r-- | comp/work/23/stack.py | 47 |
4 files changed, 84 insertions, 0 deletions
diff --git a/comp/work/22/classes.py b/comp/work/22/classes.py new file mode 100644 index 0000000..16917c1 --- /dev/null +++ b/comp/work/22/classes.py @@ -0,0 +1,20 @@ +class Human: + def __init__(self, name, height, eye): + self.__name = name + self.__height = height + self.__eye = eye + + def set_eye(self, new_color): + self.__eye = new_color + + def get_name(self): + return self.__name + + def get_eye(self): + return self.__eye + +human1 = Human('john','2cm','blue') + +human1.set_eye('green') + +print(human1.get_eye()) diff --git a/comp/work/23/higherorder.py b/comp/work/23/higherorder.py new file mode 100644 index 0000000..181c333 --- /dev/null +++ b/comp/work/23/higherorder.py @@ -0,0 +1,10 @@ +def shout(word): + return (word.upper()) + +def wisper(word): + return (word.lower()) + +def say(func): + print(func("heLLo")) + +say(shout) diff --git a/comp/work/23/recursion.py b/comp/work/23/recursion.py new file mode 100644 index 0000000..63e8e6b --- /dev/null +++ b/comp/work/23/recursion.py @@ -0,0 +1,7 @@ +def factorial(num): + if num == 0: + return 0 + else: + return num + factorial(num - 1) + +print(factorial(23)) diff --git a/comp/work/23/stack.py b/comp/work/23/stack.py new file mode 100644 index 0000000..f1cea09 --- /dev/null +++ b/comp/work/23/stack.py @@ -0,0 +1,47 @@ +class Stack: + def __init__(self, size): + self.maxSize = size + self.pointer = -1 + self.data = [] + + def peek(self): + print(self.data[self.pointer]) + + def push(self, element): + if self.pointer > self.maxSize: + exit(1) + else: + self.data.append(element) + self.pointer = self.pointer + 1 + + def pop(self): + self.data.pop() + self.pointer = self.pointer - 1 + + def isfull(self): + if len(self.data) == self.maxSize: + return True + else: + return False + + def isempty(self): + if len(self.data) == 0: + return True + else: + return False + + +mystack = Stack(10) + +myinternalstack = Stack(10) + +for i in range(10): + myinternalstack.push("hello") + + +for i in range(10): + mystack.push(myinternalstack) + +mystack.peek() + + |