diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c18dd8d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ diff --git a/README.md b/README.md index d87c62d..268b828 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,9 @@ # Exercises -## Modules -* Introduction And Environment -* Introduction To Python -* Data Structures -* Algorithms -* Software Theory +| Module ID | Module Name | +|:-----------:|:--------:| +| 1 | [Introduction and Environment](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment) | +| 2 | [Introduction to Python](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_to_python) | +| 3 | [Data Structures](https://github.com/ByteAcademyCo/Exercises/tree/master/data_structures) | +| 4 | [Algorithms](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms) | +| 5 | [Software Theory](https://github.com/ByteAcademyCo/Exercises/tree/master/software_theory) | diff --git a/algorithms/README.md b/algorithms/README.md index 2e573ce..d0c4a36 100644 --- a/algorithms/README.md +++ b/algorithms/README.md @@ -1,8 +1,9 @@ # Exercise Organization -## Exercise Sections -* Graph Traversal -* Sorting -* Bit Manipulation -* String Manipulation -* Dynamic Programming +| Section ID | Section Name | +|:-----------:|:--------:| +| 1 | [Graph Traversals](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/graph_traversal) | +| 2 | [Sorting](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/sorting) | +| 3 | [Bit Manipulation](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/bit_manipultion) | +| 4 | [String Manipulation](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/string_manipulation) | +| 5 | [Dynamic Programming](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/dynamic_programming) | diff --git a/algorithms/bit_manipultion/README.md b/algorithms/bit_manipulation/README.md similarity index 100% rename from algorithms/bit_manipultion/README.md rename to algorithms/bit_manipulation/README.md diff --git a/algorithms/graph_traversal/1_length/length.py b/algorithms/graph_traversal/1_length/length.py deleted file mode 100644 index 7dd4e3f..0000000 --- a/algorithms/graph_traversal/1_length/length.py +++ /dev/null @@ -1,15 +0,0 @@ -# A Graph is either: -# None -# Node - -class Node: - # val: int - # log: listof(Graph) - def __init__(self, val, log): - self.val = val - self.log = log - -# Write a function called len that consumes a Graph g and returns the number of Nodes in the graph -# ie. length(Node(1, [Node(2, None), Node(3, [Node(4, None)])])) -> 4 -def length(graph): - ... diff --git a/algorithms/graph_traversal/2_most_neighbors/most_neighbors.py b/algorithms/graph_traversal/2_most_neighbors/most_neighbors.py deleted file mode 100644 index 9746a3d..0000000 --- a/algorithms/graph_traversal/2_most_neighbors/most_neighbors.py +++ /dev/null @@ -1,37 +0,0 @@ -# A Graph is either: -# None -# Node - -class Node: - # val: int - # log: listof(Graph) - def __init__(self, val, log): - self.val = val - self.log = log - -# Write a function called most_neighbors that consumes a Graph g and returns the Node with the most neighbors -# ie. most_neighbors(Node(1, [Node(2, [Node(3, None), Node(4, None), Node(5, None)]), Node(2, None), Node(10, [Node(5, None), Node(3, [Node(1, None)])])])) -> Node(2, [Node(3, None), Node(4, None), Node(5, None)]) -def find_most_neighbors(log, most_neighbor): - if log is None or len(log) == 0: - return most_neighbor - else: - return max(helper(log[0], most_neighbor), find_most_neighbors(log[1:], most_neighbor)) -def helper(g, most_neighbor): - if g is None or g.log is None: - return most_neighbor - if len(g.log) > len(most_neighbor.log): - return find_most_neighbors(g.log, g) - else: - return find_most_neighbors(g.log, most_neighbor) - -def most_neighbors(g): - return find_most_neighbors(g.log, g) - -import pytest - -def test_most_neighbors(): - graph = Node(100, [Node(2, [Node(3, None), Node(4, None), Node(5, None), Node(10, None), Node(15, None)]), Node(2, None), Node(10, [Node(5, None), Node(3, [Node(1, None)])])]) - g2 = Node(1, [Node(2, [Node(3, None), Node(4, None)])]) - assert most_neighbors(graph).val == 2 - assert len(most_neighbors(graph)) == 5 - diff --git a/algorithms/graph_traversal/3_permutations/permutations.py b/algorithms/graph_traversal/3_permutations/permutations.py deleted file mode 100644 index 4e4e15b..0000000 --- a/algorithms/graph_traversal/3_permutations/permutations.py +++ /dev/null @@ -1,59 +0,0 @@ -# Write a function called permutations that consumes a list of numbers lon and returns a list of integers containing all the permutations of lon. The order of the permutations don't matter -# ie. permutations([1,2,3]) -> [123, 132, 213, 231, 312, 321] - -class Tree: - def __init__(self, lon): #[1,2,3,4,5] - self.children = [] - for i in lon: - node = Node(i) - self.children.append(node) - copy = list(lon) - copy.remove(i) - node.gen_children(copy) - - def get_perms(self): - perms = [] - for i in range(len(self.children)): - l = self.children[i].get_perms() - result = filter(lambda x: len(str(x)) == len(self.children), l) - perms.extend(list(result)) - return perms - -class Node: - def __init__(self, val): - self.val = val - self.children = [] - def gen_children(self, lon): - if lon: - for num in lon: - node = Node(int(str(self.val) + str(num))) - self.children.append(node) - copy = list(lon) - copy.remove(num) - node.gen_children(copy) - - def get_perms(self): - if self.children == []: - return [self.val] - else: - first_child = self.children[0] - self.children = self.children[1:] - return first_child.get_perms() + self.helper(self.children) - def helper(self, lon): - if lon == []: - return [] - else: - return self.get_perms() + self.helper(lon[1:]) - - -def permutations(lon): - perm_tree = Tree(lon) - perms = perm_tree.get_perms() - return perms - -import pytest -def test_permutations(): - L = [1,2,3] - perms = permutations(L) - return True if [123, 132, 213, 231, 312, 321] in perms else False - diff --git a/algorithms/graph_traversal/README.md b/algorithms/graph_traversals/README.md similarity index 100% rename from algorithms/graph_traversal/README.md rename to algorithms/graph_traversals/README.md diff --git a/data_structures/binary_trees/1_Binary_Search/README.md b/data_structures/binary_trees/1_Binary_Search/README.md new file mode 100644 index 0000000..74c438d --- /dev/null +++ b/data_structures/binary_trees/1_Binary_Search/README.md @@ -0,0 +1,15 @@ +# Binary Search + +## Motivation + + +# Problem Description +Write a Python program to find the value in a given non-empty Binary Search Tree (BST) of unique values. +Program should return value is found if value is present in tree. + + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/1_Binary_Search/Solution/solution.py b/data_structures/binary_trees/1_Binary_Search/Solution/solution.py new file mode 100644 index 0000000..d41f0ff --- /dev/null +++ b/data_structures/binary_trees/1_Binary_Search/Solution/solution.py @@ -0,0 +1,53 @@ +class Node: + + def __init__(self, data): + + self.left = None + self.right = None + self.data = data + +# Insert method to create nodes + def insert(self, data): + + if self.data: + if data < self.data: + if self.left is None: + self.left = Node(data) + else: + self.left.insert(data) + elif data > self.data: + if self.right is None: + self.right = Node(data) + else: + self.right.insert(data) + else: + self.data = data +# findval method to compare the value with nodes + def findval(self, lkpval): + if lkpval < self.data: + if self.left is None: + return str(lkpval) + return self.left.findval(lkpval) + elif lkpval > self.data: + if self.right is None: + return str(lkpval) + return self.right.findval(lkpval) + else: + return self.data +# Print the tree + def PrintTree(self): + if self.left: + self.left.PrintTree() + print( self.data), + if self.right: + self.right.PrintTree() + + +root = Node(12) +root.insert(6) +root.insert(14) +root.insert(3) +ele = input() +element = int(ele) +result = root.findval(element) +print(result) diff --git a/data_structures/binary_trees/1_Binary_Search/Solution/test_solution.py b/data_structures/binary_trees/1_Binary_Search/Solution/test_solution.py new file mode 100644 index 0000000..67eab04 --- /dev/null +++ b/data_structures/binary_trees/1_Binary_Search/Solution/test_solution.py @@ -0,0 +1,21 @@ +def test_solution(monkeypatch): + a = None + x = 2 + + def g(num1): + nonlocal a + a = num1 + + def f(): + + nonlocal x + return x + + monkeypatch.setattr('builtins.print',g) + + monkeypatch.setattr('builtins.input',f) + + import solution + assert solution.ele==x + + diff --git a/data_structures/binary_trees/1_Create_BT_Node/README.md b/data_structures/binary_trees/1_Create_BT_Node/README.md new file mode 100644 index 0000000..f8fc966 --- /dev/null +++ b/data_structures/binary_trees/1_Create_BT_Node/README.md @@ -0,0 +1,11 @@ +# Create Binary Tree With Node + +## Motivation +# Problem Description + Write a Python program that creates Binary Tree with Node + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/1_Create_BT_Node/Solution/solution.py b/data_structures/binary_trees/1_Create_BT_Node/Solution/solution.py new file mode 100644 index 0000000..200d257 --- /dev/null +++ b/data_structures/binary_trees/1_Create_BT_Node/Solution/solution.py @@ -0,0 +1,15 @@ +class Node: + + def __init__(self, data): + + self.left = None + self.right = None + self.data = data + + + def PrintTree(self): + print(self.data) + +root = Node(10) + +root.PrintTree() \ No newline at end of file diff --git a/data_structures/binary_trees/1_Create_BT_Node/Solution/test_solution.py b/data_structures/binary_trees/1_Create_BT_Node/Solution/test_solution.py new file mode 100644 index 0000000..8d08b39 --- /dev/null +++ b/data_structures/binary_trees/1_Create_BT_Node/Solution/test_solution.py @@ -0,0 +1,10 @@ +def test_solution(monkeypatch): + a = None + + def g(num1): + nonlocal a + a = num1 + + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/1_Insert_into_Tree/READE.md b/data_structures/binary_trees/1_Insert_into_Tree/READE.md new file mode 100644 index 0000000..9b49b7c --- /dev/null +++ b/data_structures/binary_trees/1_Insert_into_Tree/READE.md @@ -0,0 +1,12 @@ +# Insert Values Into a tree +## Motivation + + +# Problem Description +Write a Python program insert values into Binary Tree + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/1_Insert_into_Tree/Solution/solution.py b/data_structures/binary_trees/1_Insert_into_Tree/Solution/solution.py new file mode 100644 index 0000000..81ebcb2 --- /dev/null +++ b/data_structures/binary_trees/1_Insert_into_Tree/Solution/solution.py @@ -0,0 +1,39 @@ +class Node: + + def __init__(self, data): + + self.left = None + self.right = None + self.data = data + + def insert(self, data): +# Compare the new value with the parent node + if self.data: + if data < self.data: + if self.left is None: + self.left = Node(data) + else: + self.left.insert(data) + elif data > self.data: + if self.right is None: + self.right = Node(data) + else: + self.right.insert(data) + else: + self.data = data + +# Print the tree + def PrintTree(self): + if self.left: + self.left.PrintTree() + return self.data + if self.right: + self.right.PrintTree() + +# Use the insert method to add nodes +root = Node(12) +root.insert(6) +root.insert(14) +root.insert(3) +result = root.PrintTree() +print(result) diff --git a/data_structures/binary_trees/1_Insert_into_Tree/Solution/test_solution.py b/data_structures/binary_trees/1_Insert_into_Tree/Solution/test_solution.py new file mode 100644 index 0000000..32ad81f --- /dev/null +++ b/data_structures/binary_trees/1_Insert_into_Tree/Solution/test_solution.py @@ -0,0 +1,9 @@ +def test_solution(monkeypatch): + a = None + + def g(num1): + nonlocal a + a = num1 + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/1_length/length.py b/data_structures/binary_trees/1_length/length.py deleted file mode 100644 index 574e444..0000000 --- a/data_structures/binary_trees/1_length/length.py +++ /dev/null @@ -1,22 +0,0 @@ -# A Binary Tree (BT) is either: -# None -# Node - -class Node: - # val: int - # left: BT - # right: BT - def __init__(self, val, left, right): - self.val = val - self.left = left - self.right = right - -# Write a function called length that consumes a Binary Tree t and returns how many Nodes are in t -def length(t): - if t == None: - return 0 - return 1 + length(t.left) + length(t.right) - -def test_length(): - t = Node(1, Node(2, Node(3, None, None), None), Node(4, None, None)) - assert length(t) == 4 diff --git a/data_structures/binary_trees/2_Inorder_Travesal/README.md b/data_structures/binary_trees/2_Inorder_Travesal/README.md new file mode 100644 index 0000000..baa8cd1 --- /dev/null +++ b/data_structures/binary_trees/2_Inorder_Travesal/README.md @@ -0,0 +1,12 @@ +# Inorder Traversal +## Motivation + + +# Problem Description +Write a Python program to perform Inoreder Trversal on Bonary Tree. + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/2_Inorder_Travesal/Solution/solution.py b/data_structures/binary_trees/2_Inorder_Travesal/Solution/solution.py new file mode 100644 index 0000000..1638714 --- /dev/null +++ b/data_structures/binary_trees/2_Inorder_Travesal/Solution/solution.py @@ -0,0 +1,43 @@ +class Node: + + def __init__(self, data): + + self.left = None + self.right = None + self.data = data +# Insert Node + def insert(self, data): + + if self.data: + if data < self.data: + if self.left is None: + self.left = Node(data) + else: + self.left.insert(data) + elif data > self.data: + if self.right is None: + self.right = Node(data) + else: + self.right.insert(data) + else: + self.data = data + +# Inorder traversal +# Left -> Root -> Right + def inorderTraversal(self, root): + res = [] + if root: + res = self.inorderTraversal(root.left) + res.append(root.data) + res = res + self.inorderTraversal(root.right) + return res + +root = Node(27) +root.insert(14) +root.insert(35) +root.insert(10) +root.insert(19) +root.insert(31) +root.insert(42) +result = root.inorderTraversal(root) +print(result) \ No newline at end of file diff --git a/data_structures/binary_trees/2_Inorder_Travesal/Solution/test_solution.py b/data_structures/binary_trees/2_Inorder_Travesal/Solution/test_solution.py new file mode 100644 index 0000000..32ad81f --- /dev/null +++ b/data_structures/binary_trees/2_Inorder_Travesal/Solution/test_solution.py @@ -0,0 +1,9 @@ +def test_solution(monkeypatch): + a = None + + def g(num1): + nonlocal a + a = num1 + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/2_Postorder_Traversal/README.md b/data_structures/binary_trees/2_Postorder_Traversal/README.md new file mode 100644 index 0000000..0bb37fa --- /dev/null +++ b/data_structures/binary_trees/2_Postorder_Traversal/README.md @@ -0,0 +1,14 @@ +# Postorder Traversal + +## Motivation + + +# Problem Description +Write a Python program to perform Postorder Traversal on Binary Tree. + + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/2_Postorder_Traversal/Solution/solution.py b/data_structures/binary_trees/2_Postorder_Traversal/Solution/solution.py new file mode 100644 index 0000000..79fcc19 --- /dev/null +++ b/data_structures/binary_trees/2_Postorder_Traversal/Solution/solution.py @@ -0,0 +1,44 @@ +class Node: + + def __init__(self, data): + + self.left = None + self.right = None + self.data = data +# Insert Node + def insert(self, data): + + if self.data: + if data < self.data: + if self.left is None: + self.left = Node(data) + else: + self.left.insert(data) + elif data > self.data: + if self.right is None: + self.right = Node(data) + else: + self.right.insert(data) + else: + self.data = data + + +# Postorder traversal +# Left ->Right -> Root + def PostorderTraversal(self, root): + res = [] + if root: + res = self.PostorderTraversal(root.left) + res = res + self.PostorderTraversal(root.right) + res.append(root.data) + return res + +root = Node(27) +root.insert(14) +root.insert(35) +root.insert(10) +root.insert(19) +root.insert(31) +root.insert(42) +result = root.PostorderTraversal(root) +print(result) diff --git a/data_structures/binary_trees/2_Postorder_Traversal/Solution/test_solution.py b/data_structures/binary_trees/2_Postorder_Traversal/Solution/test_solution.py new file mode 100644 index 0000000..32ad81f --- /dev/null +++ b/data_structures/binary_trees/2_Postorder_Traversal/Solution/test_solution.py @@ -0,0 +1,9 @@ +def test_solution(monkeypatch): + a = None + + def g(num1): + nonlocal a + a = num1 + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/2_Preorder_Traversal/README.md b/data_structures/binary_trees/2_Preorder_Traversal/README.md new file mode 100644 index 0000000..190d7e4 --- /dev/null +++ b/data_structures/binary_trees/2_Preorder_Traversal/README.md @@ -0,0 +1,12 @@ +# Preorder Traversal + +## Motivation + +# Problem Description +Write a Python program to perform Preorder Traversal on Binary Tree. + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/2_Preorder_Traversal/Solution/solution.py b/data_structures/binary_trees/2_Preorder_Traversal/Solution/solution.py new file mode 100644 index 0000000..b6a325d --- /dev/null +++ b/data_structures/binary_trees/2_Preorder_Traversal/Solution/solution.py @@ -0,0 +1,43 @@ +class Node: + + def __init__(self, data): + + self.left = None + self.right = None + self.data = data +# Insert Node + def insert(self, data): + + if self.data: + if data < self.data: + if self.left is None: + self.left = Node(data) + else: + self.left.insert(data) + elif data > self.data: + if self.right is None: + self.right = Node(data) + else: + self.right.insert(data) + else: + self.data = data + +# Preorder traversal +# Root -> Left ->Right + def PreorderTraversal(self, root): + res = [] + if root: + res.append(root.data) + res = res + self.PreorderTraversal(root.left) + res = res + self.PreorderTraversal(root.right) + return res + +root = Node(27) +root.insert(14) +root.insert(35) +root.insert(10) +root.insert(19) +root.insert(31) +root.insert(42) +result = root.PreorderTraversal(root) +print(result) \ No newline at end of file diff --git a/data_structures/binary_trees/2_Preorder_Traversal/Solution/test_solution.py b/data_structures/binary_trees/2_Preorder_Traversal/Solution/test_solution.py new file mode 100644 index 0000000..32ad81f --- /dev/null +++ b/data_structures/binary_trees/2_Preorder_Traversal/Solution/test_solution.py @@ -0,0 +1,9 @@ +def test_solution(monkeypatch): + a = None + + def g(num1): + nonlocal a + a = num1 + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/2_bst/README.md b/data_structures/binary_trees/2_bst/README.md deleted file mode 100644 index c955b24..0000000 --- a/data_structures/binary_trees/2_bst/README.md +++ /dev/null @@ -1,79 +0,0 @@ -# Tree - -* You are provided with the basic code for a Binary Search Tree (BST) with \_\_init\_\_, and insert already implemented. Your goal is to implement the methods listed below in the specified runtime. Tests are provided for each implementation - * Implement \_\_len\_\_ in O(n) runtime - * Implement search in O(logn) and traverse in O(n) runtime - * Implement \_\_len\_\_ in O(1) runtime. - * Hint: Need to modify \_\_init\_\_ and possibly other methods as well - -```Python -class Node: - def __init__(self, num, left = None, right = None): - self.num = num - self.left = left - self.right = right - - def __lt__(self, other): - return self.num < other.num - - def __len__(self): - pass - - def insert(self, num): - new_node = Node(num) - if new_node < self: - if self.left == None: - self.left = new_node - else: - self.left.insert(num) - else: - if self.right == None: - self.right = new_node - else: - self.right.insert(num) - - def traverse(self, num): - pass - def search(self, num): - pass -``` - -* Initialization -```Python -t = Node(10, - Node(5, - Node(0, - None, - Node(2, None, None)), - Node(8, - None, - None)), - Node(20, - Node(15, - None, - None), - Node(30, - None, - Node(70, - None, - None)))) - -``` - -* Length -```Python -len(t) == 9 -``` - -* Search - return True if num exists, False otherwise -```Python -t.search(40) == False -t.search(70) == True -``` - -* Traverse - return a list of all the numbers in sorted order -```Python -t.traverse() == [0, 5, 8, 10, 15, 20, 30, 70] -``` - - diff --git a/data_structures/binary_trees/2_valid or not/README.md b/data_structures/binary_trees/2_valid or not/README.md new file mode 100644 index 0000000..508b0ae --- /dev/null +++ b/data_structures/binary_trees/2_valid or not/README.md @@ -0,0 +1,28 @@ +# Valid Tree Or Not a Valid Tree + +## Motivation + + +# Problem Description +Write a Python program to check whether a given a binary tree is a valid binary search tree (BST) or not. +Let a binary search tree (BST) is defined as follows: +The left subtree of a node contains only nodes with keys less than the node's key. +The right subtree of a node contains only nodes with keys greater than the node's key. +Both the left and right subtrees must also be binary search trees. + +Example 1: + 2 + / \ + 1 3 +Binary tree [2,1,3], return true. +Example 2: + 1 + / \ + 2 3 +Binary tree [1,2,3], return false. + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/binary_trees/2_valid or not/Solution/solution.py b/data_structures/binary_trees/2_valid or not/Solution/solution.py new file mode 100644 index 0000000..6dd13ab --- /dev/null +++ b/data_structures/binary_trees/2_valid or not/Solution/solution.py @@ -0,0 +1,40 @@ +class Node: + def __init__(self, k, val): + self.key = k + self.value = val + self.left = None + self.right = None + +def tree_max(node): + if not node: + return float("-inf") + maxleft = tree_max(node.left) + maxright = tree_max(node.right) + return max(node.key, maxleft, maxright) + +def tree_min(node): + if not node: + return float("inf") + minleft = tree_min(node.left) + minright = tree_min(node.right) + return min(node.key, minleft, minright) + +def verify(node): + if not node: + return True + if (tree_max(node.left) <= node.key <= tree_min(node.right) and + verify(node.left) and verify(node.right)): + return 1 # Vaild + else: + return 0 # Invalid + +# root = Node(2,"Two") +# root.left = Node(1,"one") +# root.right = Node(3,"Three") + + +root = Node(1,"one") +root.left = Node(2,"Two") +root.right = Node(3,"Three") +result = verify(root) +print(result) diff --git a/data_structures/binary_trees/2_valid or not/Solution/test_solution.py b/data_structures/binary_trees/2_valid or not/Solution/test_solution.py new file mode 100644 index 0000000..32ad81f --- /dev/null +++ b/data_structures/binary_trees/2_valid or not/Solution/test_solution.py @@ -0,0 +1,9 @@ +def test_solution(monkeypatch): + a = None + + def g(num1): + nonlocal a + a = num1 + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/3_delete a node/README.md b/data_structures/binary_trees/3_delete a node/README.md new file mode 100644 index 0000000..4551051 --- /dev/null +++ b/data_structures/binary_trees/3_delete a node/README.md @@ -0,0 +1,13 @@ +# Delete a Node from tree + +## Motivation + + +# Problem Description +Write a Python program to delete a node with the given key in a given Binary search tree (BST) + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/3_delete a node/Solution/solution.py b/data_structures/binary_trees/3_delete a node/Solution/solution.py new file mode 100644 index 0000000..1b7cab0 --- /dev/null +++ b/data_structures/binary_trees/3_delete a node/Solution/solution.py @@ -0,0 +1,56 @@ +# Definition: Binary tree node. +class TreeNode(object): + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +def delete_Node(root, key): + # if root doesn't exist, just return it + if not root: + return root + # Find the node in the left subtree if key value is less than root value + if root.val > key: + root.left = delete_Node(root.left, key) + # Find the node in right subtree if key value is greater than root value, + elif root.val < key: + root.right= delete_Node(root.right, key) + # Delete the node if root.value == key + else: + # If there is no right children delete the node and new root would be root.left + if not root.right: + return root.left + # If there is no left children delete the node and new root would be root.right + if not root.left: + return root.right + # If both left and right children exist in the node replace its value with + # the minmimum value in the right subtree. Now delete that minimum node + # in the right subtree + temp_val = root.right + while temp_val.left: + temp_val = temp_val.left + # Replace value + root.val = mini + # Delete the minimum node in right subtree + root.right = deleteNode(root.right,root.val) + return root + +def preOrder(node): + if not node: + return + return node.val + preOrder(node.left) + preOrder(node.right) + +root = TreeNode(5) +root.left = TreeNode(3) +root.right = TreeNode(6) +root.left.left = TreeNode(2) +root.left.right = TreeNode(4) +root.left.right.left = TreeNode(7) + +res1 = preOrder(root) +# print(res1) # Original +result = delete_Node(root, 4) +res2 = preOrder(result) +print(res1,res2) # After Deletion \ No newline at end of file diff --git a/data_structures/binary_trees/3_delete a node/Solution/test_solution.py b/data_structures/binary_trees/3_delete a node/Solution/test_solution.py new file mode 100644 index 0000000..31d5975 --- /dev/null +++ b/data_structures/binary_trees/3_delete a node/Solution/test_solution.py @@ -0,0 +1,13 @@ +def test_solution(monkeypatch): + a = None + b = None + + def g(num1,num2): + nonlocal a + nonlocal b + a = num1 + b = num2 + monkeypatch.setattr('builtins.print',g) + + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/3_kth smallest element/README.md b/data_structures/binary_trees/3_kth smallest element/README.md new file mode 100644 index 0000000..a0f19c2 --- /dev/null +++ b/data_structures/binary_trees/3_kth smallest element/README.md @@ -0,0 +1,15 @@ +# kth Smallest element + +## Motivation + +# Problem Description +Given the root of a binary search tree and K as input, find K-th smallest element in BST. + + + + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/3_kth smallest element/Solution/solution.py b/data_structures/binary_trees/3_kth smallest element/Solution/solution.py new file mode 100644 index 0000000..ede1ac2 --- /dev/null +++ b/data_structures/binary_trees/3_kth smallest element/Solution/solution.py @@ -0,0 +1,30 @@ +class TreeNode(object): + def __init__(self, x): + self.val = x + self.left = None + self.right = None + +def kth_smallest(root, k): + stack = [] + while root or stack: + while root: + stack.append(root) + root = root.left + root = stack.pop() + k -= 1 + if k == 0: + break + root = root.right + return root.val + +root = TreeNode(8) +root.left = TreeNode(5) +root.right = TreeNode(14) +root.left.left = TreeNode(4) +root.left.right = TreeNode(6) +root.left.right.left = TreeNode(8) +root.left.right.right = TreeNode(7) +root.right.right = TreeNode(24) +root.right.right.left = TreeNode(22) +result = kth_smallest(root,2) +print(result) \ No newline at end of file diff --git a/data_structures/binary_trees/3_kth smallest element/Solution/test_solution.py b/data_structures/binary_trees/3_kth smallest element/Solution/test_solution.py new file mode 100644 index 0000000..32ad81f --- /dev/null +++ b/data_structures/binary_trees/3_kth smallest element/Solution/test_solution.py @@ -0,0 +1,9 @@ +def test_solution(monkeypatch): + a = None + + def g(num1): + nonlocal a + a = num1 + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/3_normal BST to Balanced BST/README.md b/data_structures/binary_trees/3_normal BST to Balanced BST/README.md new file mode 100644 index 0000000..cf93521 --- /dev/null +++ b/data_structures/binary_trees/3_normal BST to Balanced BST/README.md @@ -0,0 +1,13 @@ +# normal BST to Balanced BST +## Motivation +traverse nodes in Preorder and one by one insert into a self-balancing BST + + +# Problem Description + Given a BST (Binary Search Tree) that may be unbalanced, convert it into a balanced BST that has minimum possible height. + +# Testing +* + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/binary_trees/3_normal BST to Balanced BST/Solution/solution.py b/data_structures/binary_trees/3_normal BST to Balanced BST/Solution/solution.py new file mode 100644 index 0000000..153d8a7 --- /dev/null +++ b/data_structures/binary_trees/3_normal BST to Balanced BST/Solution/solution.py @@ -0,0 +1,72 @@ +import sys +import math + +# A binary tree node has data, pointer to left child +# and a pointer to right child +class Node: + def __init__(self,data): + self.data=data + self.left=None + self.right=None + +# This function traverse the skewed binary tree and +# stores its nodes pointers in vector nodes[] +def storeBSTNodes(root,nodes): + + # Base case + if not root: + return + + # Store nodes in Inorder (which is sorted + # order for BST) + storeBSTNodes(root.left,nodes) + nodes.append(root) + storeBSTNodes(root.right,nodes) + +# Recursive function to construct binary tree +def buildTreeUtil(nodes,start,end): + + # base case + if start>end: + return None + + # Get the middle element and make it root + mid=(start+end)//2 + node=nodes[mid] + + # Using index in Inorder traversal, construct + # left and right subtress + node.left=buildTreeUtil(nodes,start,mid-1) + node.right=buildTreeUtil(nodes,mid+1,end) + return node + +# This functions converts an unbalanced BST to +# a balanced BST +def buildTree(root): + + # Store nodes of given BST in sorted order + nodes=[] + storeBSTNodes(root,nodes) + + # Constucts BST from nodes[] + n=len(nodes) + return buildTreeUtil(nodes,0,n-1) + +# Function to do preorder traversal of tree +def preOrder(root): + if not root: + return + return root.data + preOrder(root.left) + preOrder(root.right) + +if __name__=='__main__': + root = Node(10) + root.left = Node(8) + root.left.left = Node(7) + root.left.left.left = Node(6) + root.left.left.left.left = Node(5) + root = buildTree(root) + # print("Preorder traversal of balanced BST is :") + result=preOrder(root) + print(result) \ No newline at end of file diff --git a/data_structures/binary_trees/3_normal BST to Balanced BST/Solution/test_solution.py b/data_structures/binary_trees/3_normal BST to Balanced BST/Solution/test_solution.py new file mode 100644 index 0000000..74deff4 --- /dev/null +++ b/data_structures/binary_trees/3_normal BST to Balanced BST/Solution/test_solution.py @@ -0,0 +1,13 @@ +def test_solution(monkeypatch): + a = None + + + def g(num1): + nonlocal a + + a = num1 + + monkeypatch.setattr('builtins.print',g) + + + import solution \ No newline at end of file diff --git a/data_structures/binary_trees/README.md b/data_structures/binary_trees/README.md index eb92a32..fe3299c 100644 --- a/data_structures/binary_trees/README.md +++ b/data_structures/binary_trees/README.md @@ -1,9 +1,15 @@ -# Exercises for Binary Trees +# Exercises for Hello World -* 1_Length -* 1_binary_trees1 -* 1_binary_trees2 -* 1_binary_trees3 -* 2_binary_trees1 -* 2_binary_trees2 -* 3_binary_trees1 +| Exercise ID | Exercise | +|:-----------:|:--------:| +| easy_e1 | [Arithmetic](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/1_arithmetic) | +| easy_e2 | [Concatenation](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/1_concatenate) | +| easy_e3 | [Name Bindings](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/1_name_bindings) | +| easy_e4 | [Operators](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/1_operators) | +| medium_e1 | [Capture Display](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_capture_display) | +| medium_e2 | [Python Caches](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_python_caches) | +| medium_e3 | [String Arithmetic](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_string_arithmetic) | +| medium_e4 | [String Duplication](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_string_duplicate) | +| medium_e5 | [Type Checking](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_type_check) | +| hard_e1 | [Type Change](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/3_type_change) | +| hard_e2 | [User Input](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/3_user_input) | diff --git a/data_structures/dictionaries_and_arrays/1.Create_Array/README.md b/data_structures/dictionaries_and_arrays/1.Create_Array/README.md new file mode 100644 index 0000000..2e8cd01 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.Create_Array/README.md @@ -0,0 +1,16 @@ +# Create Array + +## Motivation +The main difference between the lists and arrays in python are the functions that you can perform on them, the way they store their data and their daclaration. + +Array in Python can be created by importing array module. + +## Problem Description +Write a Python script to create an array containing six integers stored in a variable `my_array` ,find its buffer information (current memory address and number of elements).store the result in a variable `buffer_info`.print `buffer_info`. +Hint:`array(data_type, value_list)` is used to create an array with data type and value list specified in its arguments + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/dictionaries_and_arrays/1.Create_Array/Solutions/solution.py b/data_structures/dictionaries_and_arrays/1.Create_Array/Solutions/solution.py new file mode 100644 index 0000000..0b01c14 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.Create_Array/Solutions/solution.py @@ -0,0 +1,5 @@ +from array import array +my_array = array('i', [10, 20, 30, 40, 50]) +buffer_info = (my_array.buffer_info()) +print(buffer_info) + diff --git a/data_structures/dictionaries_and_arrays/1.Create_Array/Solutions/test_solution.py b/data_structures/dictionaries_and_arrays/1.Create_Array/Solutions/test_solution.py new file mode 100644 index 0000000..064c951 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.Create_Array/Solutions/test_solution.py @@ -0,0 +1,9 @@ +def test_solution(monkeypatch): + ret_val1= None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1.Insert_element/Readme.md b/data_structures/dictionaries_and_arrays/1.Insert_element/Readme.md new file mode 100644 index 0000000..b8056eb --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.Insert_element/Readme.md @@ -0,0 +1,20 @@ +# Insert_element + +# Motivation +Array is a container which can hold a fix number of items and these items should be of the same type. + +Element − Each item stored in an array is called an element. + +Index − Each location of an element in an array has a numerical index, which is used to identify the element. + +## Problem Description +Write a Python script that inserts the given value in the given position of the array. +Create an array of integers stored in a variable `arr` +Ask the user to enter the position and value to insert ,store the values in `ins_pos`and +`ins_val` objects respectively.print the modified array `arr`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1.Insert_element/Solutions/solution.py b/data_structures/dictionaries_and_arrays/1.Insert_element/Solutions/solution.py new file mode 100644 index 0000000..b313235 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.Insert_element/Solutions/solution.py @@ -0,0 +1,6 @@ +from array import array +arr = array('i', [1, 2, 3, 4, 5]) +ins_pos = int(input("enter the position where value to be inserted")) +ins_val = int(input("enter the value to be insterted")) +arr.insert(ins_pos,ins_val) +print(arr) diff --git a/data_structures/dictionaries_and_arrays/1.Insert_element/Solutions/test_solution.py b/data_structures/dictionaries_and_arrays/1.Insert_element/Solutions/test_solution.py new file mode 100644 index 0000000..01bf042 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.Insert_element/Solutions/test_solution.py @@ -0,0 +1,21 @@ +def test_solution(monkeypatch): + x=[2,5] + index=-1 + ret_val= None + + def f(): + nonlocal x + nonlocal index + index+=1 + return x[index] + + def g(num): + nonlocal ret_val + ret_val=num + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.ins_pos==2 + assert solution.ins_val==5 \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1.create_update_dict/Readme.md b/data_structures/dictionaries_and_arrays/1.create_update_dict/Readme.md new file mode 100644 index 0000000..c85cd52 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.create_update_dict/Readme.md @@ -0,0 +1,16 @@ +# update dictionary + +# Motivation +Dictionaries are Python’s implementation of a data structure that is more generally known as an associative array. A dictionary consists of a collection of key-value pairs. + +You can define a dictionary by enclosing a comma-separated list of key-value pairs in curly braces ({}). A colon (:) separates each key from its associated value: + +## Problem Description +Write a Python script to create a dictionary and update the same with dictionary elements(key-value pairs).Create an empty dictionary stored in a variable `dict`.Your goal is to add 3 elements into the `dict`, try adding different data types that is int,string,list... .print `dict`. + + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1.create_update_dict/Solutions/solution.py b/data_structures/dictionaries_and_arrays/1.create_update_dict/Solutions/solution.py new file mode 100644 index 0000000..15c0f2f --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.create_update_dict/Solutions/solution.py @@ -0,0 +1,8 @@ +# Creating an empty Dictionary +Dict = {} + +# Adding elements one at a time +Dict[0] = 'Bob' +Dict[1] = 1.0 +Dict['value_set'] = 1,2,3 +print(Dict) diff --git a/data_structures/dictionaries_and_arrays/1.create_update_dict/Solutions/test_solution.py b/data_structures/dictionaries_and_arrays/1.create_update_dict/Solutions/test_solution.py new file mode 100644 index 0000000..f86ec2d --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.create_update_dict/Solutions/test_solution.py @@ -0,0 +1,10 @@ +def test_solution(monkeypatch): + ret_val= None + + def g(num): + nonlocal ret_val + ret_val=num + + monkeypatch.setattr('builtins.print',g) + + import solution \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1.print_dictionary/Readme.md b/data_structures/dictionaries_and_arrays/1.print_dictionary/Readme.md new file mode 100644 index 0000000..9ca9832 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.print_dictionary/Readme.md @@ -0,0 +1,10 @@ +# print dictionary + +## Problem Description +Write a python script to print out all the values/keys/items(anyone),from the dictionary.Create a dictionary stored in variable `dict_num`,print all the elements from the dict. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1.print_dictionary/Solutions/solution.py b/data_structures/dictionaries_and_arrays/1.print_dictionary/Solutions/solution.py new file mode 100644 index 0000000..374b808 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.print_dictionary/Solutions/solution.py @@ -0,0 +1,4 @@ +dict_num = {1: 10, 2: 20, 3: 30, 4: 40, 5: 50, 6: 60} +print("Values:") +for i in dict_num.values(): + print(i) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/1.print_dictionary/Solutions/test_solution.py b/data_structures/dictionaries_and_arrays/1.print_dictionary/Solutions/test_solution.py new file mode 100644 index 0000000..2cbce1f --- /dev/null +++ b/data_structures/dictionaries_and_arrays/1.print_dictionary/Solutions/test_solution.py @@ -0,0 +1,11 @@ +def test_solution(monkeypatch): + x= None + + def g(num1): + nonlocal x + x=num1 + + monkeypatch.setattr('builtins.print',g) + + + import solution \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.Occurance/Readme.md b/data_structures/dictionaries_and_arrays/2.Occurance/Readme.md new file mode 100644 index 0000000..41bd0f9 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Occurance/Readme.md @@ -0,0 +1,10 @@ +# Occurance + +## Problem Description +Write a Python script which asks the user for 1 integer input stored in object `element`.Create an array of integers stored in a variable `array_num`.Your goal is to compute logic to return the number of occurance of object `element` inside the array .Store the result in variable `count`.print count.. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.Occurance/Solutions/solution.py b/data_structures/dictionaries_and_arrays/2.Occurance/Solutions/solution.py new file mode 100644 index 0000000..88f305e --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Occurance/Solutions/solution.py @@ -0,0 +1,8 @@ +from array import * +array_num = array('i', [1, 3, 5, 3, 7, 9, 3]) +element = int(input("Select an element in the array to check the occurance")) +count = 0 +for i in array_num: + if i == element: + count +=1 +print(count) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.Occurance/Solutions/test_solution.py b/data_structures/dictionaries_and_arrays/2.Occurance/Solutions/test_solution.py new file mode 100644 index 0000000..d1eca10 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Occurance/Solutions/test_solution.py @@ -0,0 +1,19 @@ +def test_solution(monkeypatch): + x=3 + ret_val= None + + + def f(str): + nonlocal x + return x + + def g(num): + nonlocal ret_val + ret_val=num + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + + import solution + assert solution.element==x \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.Reverse_Array /Readme.md b/data_structures/dictionaries_and_arrays/2.Reverse_Array /Readme.md new file mode 100644 index 0000000..86a6db8 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Reverse_Array /Readme.md @@ -0,0 +1,13 @@ +# Convert JSON + +## Problem Description +Write a Python program to reverse the order of the items in the array.Create an array of integers stored in variable `array_num`.Create an empty array `reverse_array` and append the values from `array_num` in the reverse order.print `reverse_array`. + +Hint : range function takes an argument of `steps` , helps in iterating in reverse order +`(startpoint,endpoint,step)` + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.Reverse_Array /Solutions/solution.py b/data_structures/dictionaries_and_arrays/2.Reverse_Array /Solutions/solution.py new file mode 100644 index 0000000..b019890 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Reverse_Array /Solutions/solution.py @@ -0,0 +1,6 @@ +from array import * +array_num = array('i', [1, 3, 5, 3, 7, 1, 9, 3]) +reverse_array = array('i') +for i in range(len(array_num)-1,-1,-1): + reverse_array.append(array_num[i]) +print(reverse_array) diff --git a/data_structures/dictionaries_and_arrays/2.Reverse_Array /Solutions/test_solution.py b/data_structures/dictionaries_and_arrays/2.Reverse_Array /Solutions/test_solution.py new file mode 100644 index 0000000..6b26e9d --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Reverse_Array /Solutions/test_solution.py @@ -0,0 +1,11 @@ +def test_solution(monkeypatch): + ret_val= None + + def g(num): + nonlocal ret_val + ret_val=num + + monkeypatch.setattr('builtins.print',g) + + + import solution \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.Sort_values/Readme.md b/data_structures/dictionaries_and_arrays/2.Sort_values/Readme.md new file mode 100644 index 0000000..61c3198 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Sort_values/Readme.md @@ -0,0 +1,15 @@ +# Sort Values + +# Motivation +Dictionaries in Python are unsorted. They are stored by the hash value of the key, and this allows for fast lookup. + +Operator.itemgetter() takes keys of dictionaries and converts them into tuples which is then sorted.The `operator` module has to be imported for its working + +## Problem Description +Write a python program to sort the dictionary values in ascending and descending order.Create a dictionary with integer values stored in variable `my_dict`, perform the inbuilt function `operator.itemgetter()` to sort the values.Store the result in object `result`,print `result`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.Sort_values/Soultions/solution.py b/data_structures/dictionaries_and_arrays/2.Sort_values/Soultions/solution.py new file mode 100644 index 0000000..3821ea2 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Sort_values/Soultions/solution.py @@ -0,0 +1,6 @@ +import operator +my_dict = {1: 2, 3: 4, 4: 3, 2: 1, 0: 0} +results = dict(sorted(my_dict.items(), key=operator.itemgetter(1))) +print('Dictionary in ascending order by value : ',results) +results = dict(sorted(my_dict.items(), key=operator.itemgetter(1),reverse=True)) +print('Dictionary in descending order by value : ',results) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.Sort_values/Soultions/test_solution.py b/data_structures/dictionaries_and_arrays/2.Sort_values/Soultions/test_solution.py new file mode 100644 index 0000000..c656500 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.Sort_values/Soultions/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + x= None + y= None + + def g(num1,num2): + nonlocal x + nonlocal y + x=num1 + y=num2 + + monkeypatch.setattr('builtins.print',g) + + + import solution \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.convert_JSON /Readme.md b/data_structures/dictionaries_and_arrays/2.convert_JSON /Readme.md new file mode 100644 index 0000000..cd4a784 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.convert_JSON /Readme.md @@ -0,0 +1,18 @@ +# Convert JSON + +# Motivation +`JavaScript Object Notation` (JSON) is a standardized format commonly used to transfer data as text that can be sent over a network. It's used by lots of APIs and Databases. + +`json.dumps()` : The function is responsible for converting a python string into a json object + +`json.loads()` : The function is responsible for converting a json object into a python string + + +## Problem Description +Write a python function which takes an argument which defines a dictionary.Your goal is to convert the dictionary into JSON format.Define a dictionary with list of student and teacher names, pass the same in the function calling stored in a variable `result`. print the `result`.Also check the type of the `result`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/2.convert_JSON /Solutions/dictionary b/data_structures/dictionaries_and_arrays/2.convert_JSON /Solutions/dictionary new file mode 100644 index 0000000..e69de29 diff --git a/data_structures/dictionaries_and_arrays/2.convert_JSON /Solutions/solution.py b/data_structures/dictionaries_and_arrays/2.convert_JSON /Solutions/solution.py new file mode 100644 index 0000000..e150828 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.convert_JSON /Solutions/solution.py @@ -0,0 +1,13 @@ +import json +def convert(dict): + data=json.dumps(dict) + return data +my_dict = {"students":[{"firstName": "Nikki", "lastName": "Roysden"}, + {"firstName": "Mervin", "lastName": "Friedland"}, + {"firstName": "Aron ", "lastName": "Wilkins"}], +"teachers":[{"firstName": "Amberly", "lastName": "Calico"}, + {"firstName": "Regine", "lastName": "Agtarap"}]} + +result = convert(my_dict) +print(result) + diff --git a/data_structures/dictionaries_and_arrays/2.convert_JSON /Solutions/test_solution.py b/data_structures/dictionaries_and_arrays/2.convert_JSON /Solutions/test_solution.py new file mode 100644 index 0000000..6b26e9d --- /dev/null +++ b/data_structures/dictionaries_and_arrays/2.convert_JSON /Solutions/test_solution.py @@ -0,0 +1,11 @@ +def test_solution(monkeypatch): + ret_val= None + + def g(num): + nonlocal ret_val + ret_val=num + + monkeypatch.setattr('builtins.print',g) + + + import solution \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/3.Difference/Readme.md b/data_structures/dictionaries_and_arrays/3.Difference/Readme.md new file mode 100644 index 0000000..44299d8 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/3.Difference/Readme.md @@ -0,0 +1,11 @@ +# Difference + +## Problem Description + +Write a python script to compute the differerence between greatest and smallest number of the array.Create an array of integers stored in a variable `array_num`.your goal is to find greatest number and lowest number from the array stored in variables `greatest` and `lowest` respectively,find the difference of the same. Store the result in `result` object.print `result`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/3.Difference/Solutions/solution.py b/data_structures/dictionaries_and_arrays/3.Difference/Solutions/solution.py new file mode 100644 index 0000000..da71549 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/3.Difference/Solutions/solution.py @@ -0,0 +1,13 @@ +from array import array +array_num = array('i', [5, 8, 12, 15, 10, 7]) +greatest=0 +smallest=0 +for i in range(len(array_num)): + if greatestarray_num[i]: + smallest=array_num[i] +result=greatest-smallest +print(result) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/3.Difference/Solutions/test_solution.py b/data_structures/dictionaries_and_arrays/3.Difference/Solutions/test_solution.py new file mode 100644 index 0000000..6b26e9d --- /dev/null +++ b/data_structures/dictionaries_and_arrays/3.Difference/Solutions/test_solution.py @@ -0,0 +1,11 @@ +def test_solution(monkeypatch): + ret_val= None + + def g(num): + nonlocal ret_val + ret_val=num + + monkeypatch.setattr('builtins.print',g) + + + import solution \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/3.square_keys/Readme.md b/data_structures/dictionaries_and_arrays/3.square_keys/Readme.md new file mode 100644 index 0000000..45d9ddf --- /dev/null +++ b/data_structures/dictionaries_and_arrays/3.square_keys/Readme.md @@ -0,0 +1,11 @@ +# square_keys + +## Problem Description + +Write a python function that contains an input object `num`, ask the user for an input number and store it in object `num`.Your goal is to create an empty dictionary and append it with key and value pairs, where keys are numbers between `1` to `n` and the values are square of keys. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/3.square_keys/Solutions /solution.py b/data_structures/dictionaries_and_arrays/3.square_keys/Solutions /solution.py new file mode 100644 index 0000000..a2803b4 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/3.square_keys/Solutions /solution.py @@ -0,0 +1,8 @@ +def square_keys(num): + my_dict = dict() + for i in range(1,num+1): + my_dict[i]=i**2 + return my_dict +num=int(input("Input a number ")) +result = square_keys(num) +print(result) \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/3.square_keys/Solutions /test_solution.py b/data_structures/dictionaries_and_arrays/3.square_keys/Solutions /test_solution.py new file mode 100644 index 0000000..dc5649c --- /dev/null +++ b/data_structures/dictionaries_and_arrays/3.square_keys/Solutions /test_solution.py @@ -0,0 +1,19 @@ +def test_solution(monkeypatch): + x=5 + ret_val= None + + + def f(str): + nonlocal x + return x + + def g(num): + nonlocal ret_val + ret_val=num + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + + import solution + assert solution.num==x \ No newline at end of file diff --git a/data_structures/dictionaries_and_arrays/Readme.md b/data_structures/dictionaries_and_arrays/Readme.md new file mode 100644 index 0000000..a97fa15 --- /dev/null +++ b/data_structures/dictionaries_and_arrays/Readme.md @@ -0,0 +1,14 @@ +# Introduction To Arrays and Dictionary Exercises + +| Exercise ID | Exercise | +|:-----------:|:--------:| +| easy_e1 | [Create_Array](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/1.Create_Array) | +| easy_e2 | [Insert_element](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/1.Insert_element) | +| easy_e3 | [create_update_dict](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/1.create_update_dict) | +| easy_e4 | [print_dictionary](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/1.print_dictionary) | +| medium_e1 | [Occurance](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/2.Occurance) | +| medium_e2 | [Reverse_Array](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/2.Reverse_Array%20) | +| medium_e3 | [Sort_values](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/2.Sort_values) | +| medium_e4 | [convert_JSON](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/introduction_to_programming/2_type_check) | +| hard_e1 | [Difference](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/3.Difference) | +| hard_e2 | [square_keys](https://github.com/ByteAcademyCo/Data-Structures/tree/Arrays/exercises/dictionaries_and_arrays/3.square_keys) | \ No newline at end of file diff --git a/data_structures/stacks_and_queues/1_create_queue/README.md b/data_structures/stacks_and_queues/1_create_queue/README.md new file mode 100644 index 0000000..be49780 --- /dev/null +++ b/data_structures/stacks_and_queues/1_create_queue/README.md @@ -0,0 +1,17 @@ +# Create Queue + +## Motivation +A Queue follows the First-in-First-Out (FIFO) principle. It is opened from both the ends hence we can easily add elements to the back and can remove elements from the front. Python provides us with the queue module to work with queue data structure related operations. + +## Problem Description +Write a Python function that contains one queue object `queue_a` having a max size arguement value initialised to 5. +Put 5 random values to the queue object inside a function "queue" calling it from object `data` +Display the `result` object containing elements of queue. + +Hint: Queue elements are not iterable , pick a data type which is iterable. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/1_create_queue/Solution/solution.py b/data_structures/stacks_and_queues/1_create_queue/Solution/solution.py new file mode 100644 index 0000000..96b10d5 --- /dev/null +++ b/data_structures/stacks_and_queues/1_create_queue/Solution/solution.py @@ -0,0 +1,13 @@ +# Code your solution here +def queue(): + import queue + queue_a = queue.Queue(maxsize=5) # Queue is created as an object 'queue_a' + queue_a.put(9) + queue_a.put(6) + queue_a.put(7) # Data is inserted in 'queue_a' at the end using put() + queue_a.put(4) + queue_a.put(1) + return queue_a +data=queue() +result=list(data.queue) +print(result) \ No newline at end of file diff --git a/data_structures/stacks_and_queues/1_create_queue/Solution/test_solution.py b/data_structures/stacks_and_queues/1_create_queue/Solution/test_solution.py new file mode 100644 index 0000000..c6a2b69 --- /dev/null +++ b/data_structures/stacks_and_queues/1_create_queue/Solution/test_solution.py @@ -0,0 +1,12 @@ +def test_solution(monkeypatch): + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/data_structures/stacks_and_queues/1_stack_null_check/README.md b/data_structures/stacks_and_queues/1_stack_null_check/README.md new file mode 100644 index 0000000..7f789dd --- /dev/null +++ b/data_structures/stacks_and_queues/1_stack_null_check/README.md @@ -0,0 +1,19 @@ +# Stack Null Check + +## Motivation +Data structure organizes the storage in computers so that we can easily access and change data. Stacks and Queues are the earliest data structure defined in computer science. + +In stacks, elements are stored one over another, and these elements get removed in the reverse order of the arrival i.e. LIFO concept is followed. LIFO means Last in First out. + +A stack is implemented using Linked Lists + +## Problem Description +Write a Python program to create a stack object `stack_1`. +Check if the object is empty. +If empty diplay `True` else display `False`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/1_stack_null_check/Solution/solution.py b/data_structures/stacks_and_queues/1_stack_null_check/Solution/solution.py new file mode 100644 index 0000000..e170469 --- /dev/null +++ b/data_structures/stacks_and_queues/1_stack_null_check/Solution/solution.py @@ -0,0 +1,9 @@ +# Code your solution here +def check(stack_1): + if stack_1==[]: + return True + else: + return False +stack_1=[] +result=check(stack_1) +print(result) \ No newline at end of file diff --git a/data_structures/stacks_and_queues/1_stack_null_check/Solution/test_solution.py b/data_structures/stacks_and_queues/1_stack_null_check/Solution/test_solution.py new file mode 100644 index 0000000..4a43322 --- /dev/null +++ b/data_structures/stacks_and_queues/1_stack_null_check/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + x=[] + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.stack_1==x + + diff --git a/data_structures/stacks_and_queues/1_stack_push/README.md b/data_structures/stacks_and_queues/1_stack_push/README.md new file mode 100644 index 0000000..363c6bd --- /dev/null +++ b/data_structures/stacks_and_queues/1_stack_push/README.md @@ -0,0 +1,20 @@ +# Stack Push + +## Motivation +A Stack is a data structure that follows the LIFO(Last In First Out) principle. +To implement a stack, we need two simple operations: + +push - It adds an element to the top of the stack. +pop - It removes an element from the top of the stack. + + +## Problem Description +Write a Python program to create a stack object 'stack_a' containing elements 'C','Perl,'C++','Java'. +Peform a push operation adding a new element 'Python' to the top of the stack. +Display the `result`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/1_stack_push/Solution/solution.py b/data_structures/stacks_and_queues/1_stack_push/Solution/solution.py new file mode 100644 index 0000000..5d9f715 --- /dev/null +++ b/data_structures/stacks_and_queues/1_stack_push/Solution/solution.py @@ -0,0 +1,7 @@ +# Code your solution here +def push(stack_a): + stack_a.push('Python') + return stack_a +stack_a=['C','Perl','C++','Java'] +result=push(stack_a) +print(result) \ No newline at end of file diff --git a/data_structures/stacks_and_queues/1_stack_push/Solution/test_solution.py b/data_structures/stacks_and_queues/1_stack_push/Solution/test_solution.py new file mode 100644 index 0000000..2524c64 --- /dev/null +++ b/data_structures/stacks_and_queues/1_stack_push/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + x=['1','2','3','4'] + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.stack_a==x + + diff --git a/data_structures/stacks_and_queues/2_queue_front/README.md b/data_structures/stacks_and_queues/2_queue_front/README.md new file mode 100644 index 0000000..7e4ef39 --- /dev/null +++ b/data_structures/stacks_and_queues/2_queue_front/README.md @@ -0,0 +1,25 @@ +# Queue Front + +## Motivation +To implement a queue, we need two simple operations: + +enqueue - It adds an element to the end of the queue. +dequeue - It removes the element from the beginning of the queue. + +Operations on Queue + +1.Addition - It adds the element in a queue and takes place at the rear end, i.e., at the back of the queue. +2.Deletion - It consists of two conditions - If no element is present in the queue, Underflow occurs in the queue, or if a stack contains some elements then element present at the front gets deleted. +3.Traversing - It involves to visit each element of the queue. + +## Problem Description +Write a Python function that contains one object `result` which performs a function call "queue" +Initialize a `queue_a` queue object having a max size 5. +Put 5 integer values to the object. +Display the `result` of the front element from `queue_a`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/2_queue_front/Solution/solution.py b/data_structures/stacks_and_queues/2_queue_front/Solution/solution.py new file mode 100644 index 0000000..69968c5 --- /dev/null +++ b/data_structures/stacks_and_queues/2_queue_front/Solution/solution.py @@ -0,0 +1,12 @@ +# Code your solution here +def queue(): + import queue + queue_a = queue.Queue(maxsize=5) # Queue is created as an object 'queue_a' + queue_a.put(99) + queue_a.put(66) + queue_a.put(77) # Data is inserted in 'queue_a' at the end using put() + queue_a.put(44) + queue_a.put(11) + return queue_a.get() # get() takes data from from the head of the Queue +result=queue() +print(result) \ No newline at end of file diff --git a/data_structures/stacks_and_queues/2_queue_front/Solution/test_solution.py b/data_structures/stacks_and_queues/2_queue_front/Solution/test_solution.py new file mode 100644 index 0000000..c6a2b69 --- /dev/null +++ b/data_structures/stacks_and_queues/2_queue_front/Solution/test_solution.py @@ -0,0 +1,12 @@ +def test_solution(monkeypatch): + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/data_structures/stacks_and_queues/2_stack_del_item/README.md b/data_structures/stacks_and_queues/2_stack_del_item/README.md new file mode 100644 index 0000000..5eaa5e7 --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_del_item/README.md @@ -0,0 +1,22 @@ +# Stack Del Item + +## Motivation +Characteristics of Stack:- + +1.Insertion order is preserved. +2.Duplicacy is allowed in Stack. +3.Similar data-type Storage. +4.Highly useful in Parsing Operations. + +## Problem Description +Write a Python function that creates a stack object `stack_continents` containing continents 'North America', 'Europe', 'Asia', 'South America', 'Antartica', 'Australia','Africa'. +Build logic to delete the 6th element from the stack and return. +Display the `result` object having remaining continents. + +Hint: Use function del to delete the 6th element from the stack. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/2_stack_del_item/Solution/solution.py b/data_structures/stacks_and_queues/2_stack_del_item/Solution/solution.py new file mode 100644 index 0000000..258ecd5 --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_del_item/Solution/solution.py @@ -0,0 +1,8 @@ +# Code your solution here +def delete(stack_continents): + del stack_continents[5] # indexing value of the 6th element from the stack + return stack_continents + +stack_continents=['North America','Europe','Asia','South America','Antartica','Australia','Africa'] +result=delete(stack_continents) +print(result) \ No newline at end of file diff --git a/data_structures/stacks_and_queues/2_stack_del_item/Solution/test_solution.py b/data_structures/stacks_and_queues/2_stack_del_item/Solution/test_solution.py new file mode 100644 index 0000000..983f0a9 --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_del_item/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + x=['1','2','3','4','5','6','7'] + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.stack_continents==x + + diff --git a/data_structures/stacks_and_queues/2_stack_insert/README.md b/data_structures/stacks_and_queues/2_stack_insert/README.md new file mode 100644 index 0000000..184a1dd --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_insert/README.md @@ -0,0 +1,12 @@ +# Stack Insert + +## Problem Description +Write a Python program that creates a stack object `stack_planets` containing planets 'Mercury','Venus','Mars','Jupiter','Saturn','Uranus' and 'Neptune' +Build logic to insert at the 2nd index position of the object with value 'Earth' +Display the `result` containing planents. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/2_stack_insert/Solution/solution.py b/data_structures/stacks_and_queues/2_stack_insert/Solution/solution.py new file mode 100644 index 0000000..9a653d9 --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_insert/Solution/solution.py @@ -0,0 +1,8 @@ +# Code your solution here +def insert(stack_planets): + stack_planets.insert(2,'Earth') + return stack_planets + +stack_planets=['Mercury','Venus','Mars','Jupiter','Saturn','Uranus','Neptune'] +result=insert(stack_planets) +print(result) \ No newline at end of file diff --git a/data_structures/stacks_and_queues/2_stack_insert/Solution/test_solution.py b/data_structures/stacks_and_queues/2_stack_insert/Solution/test_solution.py new file mode 100644 index 0000000..0ce120c --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_insert/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + x=['1','2','3','4','5','6','7'] + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.stack_planets==x + + diff --git a/data_structures/stacks_and_queues/2_stack_pop/README.md b/data_structures/stacks_and_queues/2_stack_pop/README.md new file mode 100644 index 0000000..d1bb5b2 --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_pop/README.md @@ -0,0 +1,19 @@ +# Stack Pop + +## Motivation +Python Lists are one way to implement stack operations. Include-: + +1.Adding - It adds the elements in the stack and increases the stack size. The addition takes place at the top of the stack. +2.Deletion - It consists of two conditions, first, if no element is present in the stack, then underflow occurs in the stack, and second, if a stack contains some elements, then the topmost element gets removed. It reduces the stack size. +3.Traversing - It involves visiting each element of the stack. + +## Problem Description +Write a Python program to create a stack object `stack_fruits` containing elements 'apple','banana','orange','watermelon','grapes'. +Build logic to perform the pop operation on the object. +Display `result` of the remaining elements of the stack. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/2_stack_pop/Solution/solution.py b/data_structures/stacks_and_queues/2_stack_pop/Solution/solution.py new file mode 100644 index 0000000..cc75fbe --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_pop/Solution/solution.py @@ -0,0 +1,7 @@ +# Code your solution here +def pop(stack_fruits): + stack_fruits.pop() + return stack_fruits +stack_fruits=['apple','banana','orange','watermelon','grapes'] +result=pop(stack_fruits) +print(result) \ No newline at end of file diff --git a/data_structures/stacks_and_queues/2_stack_pop/Solution/test_solution.py b/data_structures/stacks_and_queues/2_stack_pop/Solution/test_solution.py new file mode 100644 index 0000000..d7595a6 --- /dev/null +++ b/data_structures/stacks_and_queues/2_stack_pop/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + x=['1','2','3','4','5'] + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.stack_fruits==x + + diff --git a/data_structures/stacks_and_queues/3_queue_reverse/README.md b/data_structures/stacks_and_queues/3_queue_reverse/README.md new file mode 100644 index 0000000..7721032 --- /dev/null +++ b/data_structures/stacks_and_queues/3_queue_reverse/README.md @@ -0,0 +1,22 @@ +# Queue Reverse + +## Motivation +Characteristics of Queue: + +1. Insertion order of the queue is preserved. +2. Duplicacy is allowed. +3. Useful for parsing CPU task operations. + +In this method, we will dequeue the elements from the Queue and push them into the Stack. Until the Queue becomes empty. Then we pop the elements from the Stack and enqueue them to the Queue till the stack is empty. As a result, the elements in the Queue will be reversed. + +## Problem Description +Write a Python program that reverses the elements of a queue object `Q` +Your goal is to create 2 class based structures `Stack` and `Queue` having functions "empty check()","push()","pop()". +Perform the enqueue operation by pushing random integer values to the object `Q` and store the reversed elements in another stack object `S`. Call a function "Reverse" to return the list of reversed elements. +Print the `result`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/3_queue_reverse/Solution/solution.py b/data_structures/stacks_and_queues/3_queue_reverse/Solution/solution.py new file mode 100644 index 0000000..a9a5973 --- /dev/null +++ b/data_structures/stacks_and_queues/3_queue_reverse/Solution/solution.py @@ -0,0 +1,32 @@ +class Stack: + def __init__(node): + node.data = [] + def Empty(node): + return node.data == [] + def push(node, data): + node.data.append(data) + def pop(node): + return node.data.pop() +class Queue: + def __init__(node): + node.data = [] + def Empty(node): + return node.data == [] + def enQueue(node, data): + node.data.insert(0,data) + def deQueue(node): + return node.data.pop() +def Reverse(): + while( not Q.Empty()): + S.push(Q.deQueue()) + while( not S.Empty()): + Q.enQueue(S.pop()) +S = Stack() +Q = Queue() +Q.enQueue(5) +Q.enQueue(4) +Q.enQueue(3) +Q.enQueue(2) +Q.enQueue(1) +Reverse() +print(Q.data) \ No newline at end of file diff --git a/data_structures/stacks_and_queues/3_queue_reverse/Solution/test_solution.py b/data_structures/stacks_and_queues/3_queue_reverse/Solution/test_solution.py new file mode 100644 index 0000000..c6a2b69 --- /dev/null +++ b/data_structures/stacks_and_queues/3_queue_reverse/Solution/test_solution.py @@ -0,0 +1,12 @@ +def test_solution(monkeypatch): + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/data_structures/stacks_and_queues/3_queue_sort/README.md b/data_structures/stacks_and_queues/3_queue_sort/README.md new file mode 100644 index 0000000..5730ff1 --- /dev/null +++ b/data_structures/stacks_and_queues/3_queue_sort/README.md @@ -0,0 +1,19 @@ +# Queue Sort + + +## Problem Description +Write a Python program that creates a queue object `q` and put random integer values. +Construct logic using functions to sort the elements of the queue in ascending order. + +Create one `min` function which returns index of minimum element and `mintorear` function which moves the minimum element to the rear of the queue. + +Finally create a function `sort` which performs recursive operation on the above two functions `min` and `mintorear` to sort the elements and print the output + +Dislay the reversed `q`. + + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/3_queue_sort/Solution/solution.py b/data_structures/stacks_and_queues/3_queue_sort/Solution/solution.py new file mode 100644 index 0000000..9409bba --- /dev/null +++ b/data_structures/stacks_and_queues/3_queue_sort/Solution/solution.py @@ -0,0 +1,56 @@ + # Queue elements after sortedIndex are +# already sorted. This function returns +# index of minimum element from front to +# sorted_ndex +def min(q, sorted_index): + min_index = -1 + min_val = 999999999999 + n = q.qsize() + for i in range(n): + curr = q.queue[0] + q.get() + + # we add the condition i <= sorted_index + # because we don't want to traverse + # on the sorted part of the queue, + # which is the right part. + if (curr <= min_val and i <= sorted_index): + min_index = i + min_val = curr + q.put(curr) + return min_index + +# Moves given minimum element to +# rear of queue +def mintorear(q, min_index): + min_val = None + n = q.qsize() + for i in range(n): + curr = q.queue[0] + q.get() + if (i != min_index): + q.put(curr) + else: + min_val = curr + q.put(min_val) + +def sort(q): + for i in range(1, q.qsize() + 1): + min_index = min(q, q.qsize() - i) + mintorear(q, min_index) + +if __name__ == '__main__': + from queue import Queue + q = Queue() + q.put(20) + q.put(11) + q.put(51) + q.put(7) + + # Sort queue + sort(q) + + # Presorted queue + while (q.empty() == False): + print(q.queue[0], end = " ") + q.get() \ No newline at end of file diff --git a/data_structures/stacks_and_queues/3_queue_sort/Solution/test_solution.py b/data_structures/stacks_and_queues/3_queue_sort/Solution/test_solution.py new file mode 100644 index 0000000..6767448 --- /dev/null +++ b/data_structures/stacks_and_queues/3_queue_sort/Solution/test_solution.py @@ -0,0 +1,16 @@ +def test_solution(monkeypatch): + ret_val1= None + space=" " + + def g(num1,num2): + nonlocal ret_val1 + nonlocal space + ret_val1=num1 + space=num2 + + monkeypatch.setattr('builtins.print',g) + + import solution + + + diff --git a/data_structures/stacks_and_queues/3_stack_middle_del/README.md b/data_structures/stacks_and_queues/3_stack_middle_del/README.md new file mode 100644 index 0000000..d054bbc --- /dev/null +++ b/data_structures/stacks_and_queues/3_stack_middle_del/README.md @@ -0,0 +1,20 @@ +# Stack Delete Middle + +## Motivation +Delete middle element of a stack + +Given a stack with push(), pop(), empty() operations, delete middle of it without using any additional data structure. + +The idea is to use recursive calls. We first remove all items one by one, then we recur. After recursive calls, we push all items back except the middle item. + +## Problem Description +Write a Python program to delete the middle element of a stack object `st` containing random string integer values. +Your goal is to create a class based structure `Stack` containing different stack_operations. +Create a function `deletemid` which performs logic to delete the middle element of the stack `st` +Display the `result` of the remaining elements of the stack. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/data_structures/stacks_and_queues/3_stack_middle_del/Solution/solution.py b/data_structures/stacks_and_queues/3_stack_middle_del/Solution/solution.py new file mode 100644 index 0000000..e8cc755 --- /dev/null +++ b/data_structures/stacks_and_queues/3_stack_middle_del/Solution/solution.py @@ -0,0 +1,61 @@ +# code to delete middle of a stack +# without using additional data structure. + +# Deletes middle of stack of size n. Curr is current item number +class Stack: + def __init__(self): + self.items = [] + + def isEmpty(self): + return self.items == [] + + def push(self, item): + self.items.append(item) + + def pop(self): + return self.items.pop() + + def peek(self): + return self.items[len(self.items)-1] + + def size(self): + return len(self.items) + +def deletemid(st, n, curr) : + + # If stack is empty or all items + # are traversed + if (st.isEmpty() or curr == n) : + return + + # Remove current item + x = st.peek() + st.pop() + + # Remove other items + deletemid(st, n, curr+1) + + # Put all items back except middle + if (curr != int(n/2)) : + st.push(x) + +if __name__ == '__main__': + st = Stack() + +# push elements into the stack + st.push('1') + st.push('2') + st.push('3') + st.push('4') + st.push('5') + st.push('6') + st.push('7') + + deletemid(st, st.size(), 0) + +# Printing stack after deletion +# of middle. + while (st.isEmpty() == False) : + p = st.peek() + st.pop() + print (p, end=" ") \ No newline at end of file diff --git a/data_structures/stacks_and_queues/3_stack_middle_del/Solution/test_solution.py b/data_structures/stacks_and_queues/3_stack_middle_del/Solution/test_solution.py new file mode 100644 index 0000000..5cff1ef --- /dev/null +++ b/data_structures/stacks_and_queues/3_stack_middle_del/Solution/test_solution.py @@ -0,0 +1,16 @@ +def test_solution(monkeypatch): + ret_val1= None + space=" " + + def g(num1,num2): + nonlocal ret_val1 + nonlocal space + ret_val1=num1 + space=num2 + + monkeypatch.setattr('builtins.print',g) + + import solution + + + diff --git a/data_structures/stacks_and_queues/README.md b/data_structures/stacks_and_queues/README.md index 1be0c91..384793d 100644 --- a/data_structures/stacks_and_queues/README.md +++ b/data_structures/stacks_and_queues/README.md @@ -1,8 +1,14 @@ -# Exercises for stacks and queues +# Exercises - Stacks And Queues -* 1_stacks_and_queues1 -* 1_stacks_and_queues2 -* 1_stacks_and_queues3 -* 2_stacks_and_queues1 -* 2_stacks_and_queues2 -* 3_stacks_and_queues1 +| Exercise ID | Exercise | +|:-----------:|:--------:| +| easy_e1 | [Create Queue] | +| easy_e2 | [Stack Null Check] | +| easy_e3 | [Stack Push] | +| medium_e1 | [Queue Front] | +| medium_e2 | [Stack Del Item] | +| medium_e3 | [Stack Insert] | +| medium_e4 | [Stack Pop] | +| hard_e1 | [Queue Reverse] | +| hard_e2 | [Stack Mid Del] | +| hard_e3 | [Queue Sort] | diff --git a/introduction_and_environment/README.md b/introduction_and_environment/README.md index 159a53f..aa670fd 100644 --- a/introduction_and_environment/README.md +++ b/introduction_and_environment/README.md @@ -1,8 +1,9 @@ # Exercise Organization -## Exercise Sections -* UNIX and Bash -* Data Types and Control Flow -* git -* Introduction to Programming -* Hello World +| Section ID | Section Name | +|:-----------:|:--------:| +| 1 | [Hello World]() | +| 2 | [UNIX and Bash]() | +| 3 | [git]() | +| 4 | [Introduction to Programming]() | +| 5 | [Data Types and Control Flow]() | diff --git a/introduction_and_environment/data_types_and_control_flow/1_compare_check/README.md b/introduction_and_environment/data_types_and_control_flow/1_compare_check/README.md new file mode 100644 index 0000000..6436eda --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_compare_check/README.md @@ -0,0 +1,17 @@ +# Compare Check + +## Motivation +Python provides == operator to check if the object on LHS and RHS hold similar values. + +!= for not equal values. + +## Problem Description +Write a python script that contains 2 integers `x` and `y` variable values whos contents is hidden from you. +Create a variable `result` to check if x and y hold same values or not. +Print the boolean result . + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/test_solution.py new file mode 100644 index 0000000..967cdb7 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_compare_check/Solution/test_solution.py @@ -0,0 +1,15 @@ + +def test_solution(monkeypatch): + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.x==200 + assert solution.y==201 + + diff --git a/introduction_and_environment/data_types_and_control_flow/1_even_odd/README.md b/introduction_and_environment/data_types_and_control_flow/1_even_odd/README.md new file mode 100644 index 0000000..8f1c3cb --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_even_odd/README.md @@ -0,0 +1,15 @@ +# Even Odd + +## Motivation +Natural numbers are either even or odd in nature. How do we check !? + +## Problem Description +Write a Python script that asks the user for an integer stored in object `number`. +Construct logic using If-Else where you check whether the number is `Even` or `Odd` and store result in `data` variable. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/test_solution.py new file mode 100644 index 0000000..3c17606 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_even_odd/Solution/test_solution.py @@ -0,0 +1,20 @@ +def test_solution(monkeypatch): + x=744 + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.number==x + + + diff --git a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py index 1d2215e..e69de29 100644 --- a/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py +++ b/introduction_and_environment/data_types_and_control_flow/1_list_max/solution/solution.py @@ -1,3 +0,0 @@ -from provided_code import L - -LIST_MAX = 0 diff --git a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/README.md b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/README.md new file mode 100644 index 0000000..9f72426 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/README.md @@ -0,0 +1,15 @@ +# Loop Divisible + +## Motivation +Generate sequence of numbers which are divisible for 5 and 7 , having a limit range of upto 50. + +## Problem Description +Write a Python script that declares a variable `x` containing value hidden from you. +Construct a loop to run upto length of `x` to retrieve values which are divisible by 5 and 7 , store the result values in `data` variable. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py new file mode 100644 index 0000000..cbc031a --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/solution.py @@ -0,0 +1,2 @@ +# Code your solution here + \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/test_solution.py new file mode 100644 index 0000000..4affda4 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_loop_divisibility/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + y=50 + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.x==y + + + diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_convert/README.md b/introduction_and_environment/data_types_and_control_flow/1_string_convert/README.md new file mode 100644 index 0000000..2b0085d --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_convert/README.md @@ -0,0 +1,15 @@ +# String Convert + +## Motivation +By default the input() keyword captures data in a string format unless we try to explicitly type cast. + +## Problem Description +Write a Python script that asks the user for a string value stored in object `string`. +Your goal is to check whether the value is in upperCase ,if so convert the data into lowerCase else if value is in lowerCase , convert the data into upperCase and store the result in `data` variable. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/test_solution.py new file mode 100644 index 0000000..0054635 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_convert/Solution/test_solution.py @@ -0,0 +1,21 @@ +def test_solution(monkeypatch): + x='UNIVERSE' + y='universe' + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.string==x or solution.string==y + + + diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_length/README.md b/introduction_and_environment/data_types_and_control_flow/1_string_length/README.md new file mode 100644 index 0000000..fc518c6 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_length/README.md @@ -0,0 +1,15 @@ +# String length + +## Motivation +Python provides inbuilt keyword len() used to retrieve the length of any data type. + +## Problem Description +Write a Python script that asks the user for a string_value and store it object `string_1`. +Find the length of the string and store the result in `data` variable. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/test_solution.py new file mode 100644 index 0000000..04640fa --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_length/Solution/test_solution.py @@ -0,0 +1,18 @@ + +def test_solution(monkeypatch): + x='Hello' + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.string_1==x \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_slice/README.md b/introduction_and_environment/data_types_and_control_flow/1_string_slice/README.md new file mode 100644 index 0000000..f9e8733 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_slice/README.md @@ -0,0 +1,19 @@ +# String Slice + +## Motivation +Strings are sequential, immutable, collections of zero or more letters, numbers and other symbols. We call these letters, numbers and other symbols characters. String values are differentiated from identifiers by using quotation marks (either single or double). + +The operations on Lists and strings are exactly the same EXCEPT that strings are immutable and cannot be modified. To modify a string, the .replace() method must be used an must be set to another variable + +## Problem Description +Write a python script that contains a `string_value` variable holding data "Hello universe" +Perform slicing of "Hello" from `string_value` variable and store the result in `data` variable. +Concatenate `data` variable with string value "World" and store result in another variable `data_val`. +Print the result data. + + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/__pycache__/solution.cpython-37.pyc b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/__pycache__/solution.cpython-37.pyc new file mode 100644 index 0000000..492f7a9 Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/__pycache__/solution.cpython-37.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc new file mode 100644 index 0000000..947223e Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/test_solution.py new file mode 100644 index 0000000..c7da117 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/1_string_slice/Solution/test_solution.py @@ -0,0 +1,13 @@ + + +def test_solution(monkeypatch): + ret_val1=None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.string_value=="Hello Universe" + assert solution.data=="Hello" \ No newline at end of file diff --git a/introduction_and_environment/data_types_and_control_flow/2_add_item/README.md b/introduction_and_environment/data_types_and_control_flow/2_add_item/README.md new file mode 100644 index 0000000..d8cfd79 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_add_item/README.md @@ -0,0 +1,15 @@ +# Add Item + +## Motivation +Dictionary is a collection of ordered or unordered key:value pairs. + +## Problem Description +Write a python script that contains a `dict_a` dictionary variable holding a set of key:value pairs hidden from you. +Your objective is to add a new key:value pair to th existing dictionary set and store insdie variable `dict_val`. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/test_solution.py new file mode 100644 index 0000000..02667ae --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_add_item/Solution/test_solution.py @@ -0,0 +1,13 @@ + + +def test_solution(monkeypatch): + ret_val1=None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/introduction_and_environment/data_types_and_control_flow/2_append/README.md b/introduction_and_environment/data_types_and_control_flow/2_append/README.md new file mode 100644 index 0000000..357f7e5 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_append/README.md @@ -0,0 +1,15 @@ +# Append + +## Motivation +Python collective data type list provides mutable operations like index, slicing, pop, append etc. + +## Problem Description +Write a python script contains a `list_a` list variable holding items hidden from you. +Your goal is to insert a new item at the 3rd position of the list and store the result in another variable `list_b`. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/__pycache__/solution.cpython-37.pyc b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/__pycache__/solution.cpython-37.pyc new file mode 100644 index 0000000..cd23529 Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/__pycache__/solution.cpython-37.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc new file mode 100644 index 0000000..4d175a3 Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/2_append/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/test_solution.py new file mode 100644 index 0000000..02667ae --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_append/Solution/test_solution.py @@ -0,0 +1,13 @@ + + +def test_solution(monkeypatch): + ret_val1=None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/introduction_and_environment/data_types_and_control_flow/2_except_letter/README.md b/introduction_and_environment/data_types_and_control_flow/2_except_letter/README.md new file mode 100644 index 0000000..5d8f03c --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_except_letter/README.md @@ -0,0 +1,14 @@ +# Except Letter + +## Motivation +Vowels are 'a' | 'e' | 'i' | 'o' | 'u' . "BYTE ACADEMY"- Let us ignore the vowels from the Brand. + +## Problem Description +Write a Python script that declares a variable `string` which contains value `BYTE ACADEMY`. +Construct a loop to run upto length of `string` and check whether each character is a vowel or not. If not vowel , store the result of characters in another variable `data`. +Print the result. +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/test_solution.py new file mode 100644 index 0000000..20d9403 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_except_letter/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + x="BYTE ACADEMY" + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.string==x + + diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/README.md b/introduction_and_environment/data_types_and_control_flow/2_farm_area/README.md new file mode 100644 index 0000000..1838e75 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/README.md @@ -0,0 +1,15 @@ +# Farm Area + +## Motivation +A Farmers field has length and breadth in feet. + +## Problem Description +Write a Python script that asks the user to enter the field values of length and bredth in objects `length` and `bredth`. +Your goal is to compute the area of the farmers field and store the result in variable `data`. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/test_solution.py new file mode 100644 index 0000000..55b4bd7 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_farm_area/Solution/test_solution.py @@ -0,0 +1,24 @@ +def test_solution(monkeypatch): + x=[6,4] + index=-1 + ret_val1= None + + def f(): + nonlocal index + nonlocal x + index+=1 + return x[index] + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.length==6 + assert solution.breadth==4 + + + diff --git a/introduction_and_environment/data_types_and_control_flow/2_remove_item/README.md b/introduction_and_environment/data_types_and_control_flow/2_remove_item/README.md new file mode 100644 index 0000000..9bd09c4 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_remove_item/README.md @@ -0,0 +1,12 @@ +# Remove-Item + +## Problem Description +Write a python script that contains a `list_1` list variable holding items hidden from you. +Your goal is to remove an item from the list and store the result in another variable `lister`. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/test_solution.py new file mode 100644 index 0000000..7d18da9 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_remove_item/Solution/test_solution.py @@ -0,0 +1,14 @@ + + + +def test_solution(monkeypatch): + ret_val1=None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/introduction_and_environment/data_types_and_control_flow/2_sum_list/README.md b/introduction_and_environment/data_types_and_control_flow/2_sum_list/README.md new file mode 100644 index 0000000..dd87a11 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_sum_list/README.md @@ -0,0 +1,15 @@ +# Sum List + +## Motivation +List contains a set of elements maybe of same/different data type. + +## Problem Description +Write a python script that contains a `list_a` list variable holding items hidden from you. +Your goal is to sum the integer items from the list and store it in anotehr variable `total` +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/test_solution.py new file mode 100644 index 0000000..02667ae --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_sum_list/Solution/test_solution.py @@ -0,0 +1,13 @@ + + +def test_solution(monkeypatch): + ret_val1=None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/README.md b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/README.md new file mode 100644 index 0000000..3292a38 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/README.md @@ -0,0 +1,17 @@ +# Vowel / Consosnant + +## Motivation +Letters captured from the input method consists of combinations of characters, numbers, vowels and consosnants. +logic building here involves retreiving only vowels or consonants. + +## Problem Description +Write a Python script that asks the user for a character and declare in object `letter`. +Your goal is to check whether the character is a vowel or consonent and store the appropriate result in variable `data`. +Print the result. + + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/test_solution.py new file mode 100644 index 0000000..0774f5d --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/2_vowel_consonant/Solution/test_solution.py @@ -0,0 +1,21 @@ +def test_solution(monkeypatch): + x=['e','x'] + index=-1 + ret_val1= None + + def f(): + nonlocal x + nonlocal index + index+=1 + return x[index] + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/README.md b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/README.md new file mode 100644 index 0000000..56fa6f8 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/README.md @@ -0,0 +1,15 @@ +# Count Duplicate + +## Motivation +List can contain multiple duplicate elements . We can check the occurrence of the duplicate items. + +## Problem Description +Write a python script that contains a `list_dup` list variable holding duplicate items hidden from you. +Your goal is to count the number of duplicates for a particular item and store the result in `tot` variable. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/__pycache__/solution.cpython-37.pyc b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/__pycache__/solution.cpython-37.pyc new file mode 100644 index 0000000..eee6ea4 Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/__pycache__/solution.cpython-37.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc new file mode 100644 index 0000000..65946cc Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/test_solution.py new file mode 100644 index 0000000..02667ae --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_count_duplicate/Solution/test_solution.py @@ -0,0 +1,13 @@ + + +def test_solution(monkeypatch): + ret_val1=None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/README.md b/introduction_and_environment/data_types_and_control_flow/3_grade/README.md new file mode 100644 index 0000000..b42b196 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/README.md @@ -0,0 +1,22 @@ +# Grade + +## Motivation +Student Grade determines the next step to success. + ++ 90-100 -> A+ GRADE ++ 70-90-> B GRADE ++ 50-70-> C GRADE ++ 35-50-> D GRADE ++ Less than 35-> FAIL + +## Problem Description +Write a Python script that asks the user for the marks value residing in object `marks`. +Construct a series of If-Else conditioning in order to check under which grade the marks fall under category. +Store the result in variable `grade`. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/__pycache__/solution.cpython-37.pyc b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/__pycache__/solution.cpython-37.pyc new file mode 100644 index 0000000..59bd5fe Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/__pycache__/solution.cpython-37.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc new file mode 100644 index 0000000..a1a3317 Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/test_solution.py new file mode 100644 index 0000000..f8dc6b2 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_grade/Solution/test_solution.py @@ -0,0 +1,21 @@ +def test_solution(monkeypatch): + x=80 + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.mark==x + + + + diff --git a/introduction_and_environment/data_types_and_control_flow/3_month_days/README.md b/introduction_and_environment/data_types_and_control_flow/3_month_days/README.md new file mode 100644 index 0000000..01f1933 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_month_days/README.md @@ -0,0 +1,19 @@ +# Month Days + +## Motivation +Each month contains different number of overall days. From the month name , I can easily tell the number of overall days. + +## Problem Description +Write a Python script that asks the user for an wtring value associated with any month of the calendar year. +Store it in an object `month`. + +Your goal is to check whether the `month` exists in an alredy defined dictionary variable `month_dict` contais key:value pairs of MonthName:TotalMonthDaysInTheMonth format. + +If `month` exists- retrieve the TotalMothDayInTheMonth value from the dictionary w.r.t `month` and store the value in variable `data` +Print the result + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/test_solution.py new file mode 100644 index 0000000..b20f610 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_month_days/Solution/test_solution.py @@ -0,0 +1,20 @@ +def test_solution(monkeypatch): + x='august' + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.month==x + + + diff --git a/introduction_and_environment/data_types_and_control_flow/3_palindrome/README.md b/introduction_and_environment/data_types_and_control_flow/3_palindrome/README.md new file mode 100644 index 0000000..70493f9 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_palindrome/README.md @@ -0,0 +1,16 @@ +# Palindrome + +## Motivation +A string is a palindrome if it is identical forward and backward. For example “anna”, +“civic”, “level” and “hannah” are all examples of palindromicwords. + +## Problem Description +Write a Python script that asks the user for a string value stored in object `line`. +Your goal is to check whether the object is a palindrome or not . Store the result in variable `is_palindrome`. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/test_solution.py new file mode 100644 index 0000000..e5f09b2 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_palindrome/Solution/test_solution.py @@ -0,0 +1,20 @@ +def test_solution(monkeypatch): + x='malayalam' + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.line==x + + + diff --git a/introduction_and_environment/data_types_and_control_flow/3_set_difference/README.md b/introduction_and_environment/data_types_and_control_flow/3_set_difference/README.md new file mode 100644 index 0000000..b703804 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_set_difference/README.md @@ -0,0 +1,20 @@ +# Set-Diff + +## Motivation +Sets in python are same as sets in mathematics. + ++ '|' set union ++ '-' set difference ++ '<=' set subset ++ '&' set intersection + +## Problem Description +Write a python script that contains a `set_1` and `set_2` set variables holding items hidden from you. +Your goal is to find the differences between the two sets and store the result in `result` variable. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/test_solution.py new file mode 100644 index 0000000..b7403fa --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_set_difference/Solution/test_solution.py @@ -0,0 +1,11 @@ +def test_solution(monkeypatch): + ret_val1=None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/README.md b/introduction_and_environment/data_types_and_control_flow/3_shape_check/README.md new file mode 100644 index 0000000..a0d5d50 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_shape_check/README.md @@ -0,0 +1,15 @@ +# Shape Check + +## Motivation + 3-Triangle , 4-Quadrilateral , 5-Pentagon , 6-Hexagon, 7-Heptagon, 8-Octagon, 9-Nonagon are just few shapes in geometry ranging 3-9. + +## Problem Description +Write a Python script that asks the user for a geometric shape value stored in object `figure`. +Your goal is to check if object belongs to any of the geometric shape values described in the Motivation to return a result w.r.t its geometric shape name, store the result in variable `data`. +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/__pycache__/solution.cpython-37.pyc b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/__pycache__/solution.cpython-37.pyc new file mode 100644 index 0000000..78b0c20 Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/__pycache__/solution.cpython-37.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc new file mode 100644 index 0000000..a4b4371 Binary files /dev/null and b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc differ diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/test_solution.py new file mode 100644 index 0000000..c5e4e27 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_shape_check/Solution/test_solution.py @@ -0,0 +1,20 @@ +def test_solution(monkeypatch): + x='5' + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.figure==x + + + diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/README.md b/introduction_and_environment/data_types_and_control_flow/3_string_case/README.md new file mode 100644 index 0000000..2cff220 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/README.md @@ -0,0 +1,15 @@ +# String Case + +## Motivation +String values can have a mix of upper case and lower case letters. Python has inbuilt methods to convert from one case to another. + +## Problem Description +Write a Python script that asks the user for a string value residing inside object `string_val`. +Convert the value into upperCase and lowerCase and store the results in variables `upper_data` and `lower_data` respectively. +Print the results. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/test_solution.py b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/test_solution.py new file mode 100644 index 0000000..e814eba --- /dev/null +++ b/introduction_and_environment/data_types_and_control_flow/3_string_case/Solution/test_solution.py @@ -0,0 +1,23 @@ +def test_solution(monkeypatch): + x='Beautiful World' + ret_val1= None + ret_val2= None + + def f(): + nonlocal x + return x + + def g(num1,num2): + nonlocal ret_val1 + nonlocal ret_val2 + ret_val1=num1 + ret_val2=num2 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.string_val==x + + + diff --git a/introduction_and_environment/data_types_and_control_flow/README.md b/introduction_and_environment/data_types_and_control_flow/README.md index 64e9f70..8218716 100644 --- a/introduction_and_environment/data_types_and_control_flow/README.md +++ b/introduction_and_environment/data_types_and_control_flow/README.md @@ -1,7 +1,24 @@ # Exercises for Data Types and Control Flow - -* 1-List-Max -* 1-Data-Types-And-Control-Flow-2 -* 2-Data-Types-And-Control-Flow-1 -* 2-Data-Types-And-Control-Flow-2 -* 3-Data-Types-And-Control-Flow-1 +| **Exercise ID** | **Exercise** | +|:---------------:|:-------------------:| +| easy_e1 | [Compare Check](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/1_compare_check) | +| easy_e2 | [Even Odd](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/1_even_odd) | +| easy_e3 | [List Max](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/1_list_max) | +| easy_e4 | [Loop Divisibility](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/1_loop_divisibility) | +| easy_e5 | [String Convert](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/1_string_convert) | +| easy_e6 | [String Length](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/1_string_length) | +| easy_e7 | [String Slice](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/1_string_slice) | +| medium_e1 | [Add Item](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/2_add_item) | +| medium_e2 | [Append](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/2_append) | +| medium_e3 | [Except Letter](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/2_except_letter) | +| medium_e4 | [Farm Area](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/2_farm_area) | +| medium_e5 | [Remove Item](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/2_remove_item) | +| medium_e6 | [Sum List](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/2_sum_list) | +| medium_e7 | [Vowel Consonant](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/2_vowel_consonant) | +| hard_e1 | [Count Duplicate](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/3_count_duplicate) | +| hard_e2 | [Grade](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/3_grade) | +| hard_e3 | [Month Days](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/3_month_days) | +| hard_e4 | [Palindrome](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/3_palindrome) | +| hard_e5 | [Set Difference](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/3_set_difference) | +| hard_e6 | [Shape Check](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/3_shape_check) | +| hard_e7 | [String Case](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/data_types_and_control_flow/3_string_case) | diff --git a/introduction_and_environment/git/1_creating_a_repository/README.md b/introduction_and_environment/git/1_creating_a_repository/README.md new file mode 100644 index 0000000..c1256d2 --- /dev/null +++ b/introduction_and_environment/git/1_creating_a_repository/README.md @@ -0,0 +1,12 @@ +# Creating a repository + +## Problem Description +Which of the following commands creates a repository? + +a) `git init` +b) `git add` +c) `git commit` +d) `git push` + +## Submission +* Declare a variable called `answer` in *solution.py* and assign it to either 'a', 'b', 'c' or 'd'. diff --git a/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py b/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py new file mode 100644 index 0000000..cccdee2 --- /dev/null +++ b/introduction_and_environment/git/1_creating_a_repository/Solution/solution.py @@ -0,0 +1,2 @@ +# Code your solution here +answer = '' diff --git a/introduction_and_environment/git/1_creating_a_repository/Solution/test_solution.py b/introduction_and_environment/git/1_creating_a_repository/Solution/test_solution.py new file mode 100644 index 0000000..0869fce --- /dev/null +++ b/introduction_and_environment/git/1_creating_a_repository/Solution/test_solution.py @@ -0,0 +1,5 @@ + +def test_solution(): + import solution + assert solution.answer in {'a', 'A'} + diff --git a/introduction_and_environment/git/1_remote_repository/README.md b/introduction_and_environment/git/1_remote_repository/README.md new file mode 100644 index 0000000..e3bd575 --- /dev/null +++ b/introduction_and_environment/git/1_remote_repository/README.md @@ -0,0 +1,12 @@ +# Remote Repository + +## Problem Description +Which of the following synchronizes your local repository and the remote repository? + +a) `git init` +b) `git add` +c) `git commit` +d) `git push` + +## Submission +* Declare a variable called `answer` in *solution.py* and assign it to either 'a', 'b', 'c' or 'd'. diff --git a/introduction_and_environment/git/1_remote_repository/Solution/solution.py b/introduction_and_environment/git/1_remote_repository/Solution/solution.py new file mode 100644 index 0000000..cccdee2 --- /dev/null +++ b/introduction_and_environment/git/1_remote_repository/Solution/solution.py @@ -0,0 +1,2 @@ +# Code your solution here +answer = '' diff --git a/introduction_and_environment/git/1_remote_repository/Solution/test_solution.py b/introduction_and_environment/git/1_remote_repository/Solution/test_solution.py new file mode 100644 index 0000000..ea906fd --- /dev/null +++ b/introduction_and_environment/git/1_remote_repository/Solution/test_solution.py @@ -0,0 +1,5 @@ + +def test_solution(): + import solution + assert solution.answer in {'d', 'D'} + diff --git a/introduction_and_environment/git/1_staging_area/README.md b/introduction_and_environment/git/1_staging_area/README.md new file mode 100644 index 0000000..d29a15a --- /dev/null +++ b/introduction_and_environment/git/1_staging_area/README.md @@ -0,0 +1,12 @@ +# Staging Area + +## Problem Description +Which of the following commands syncronizes the staging area with your repository? + +a) `git init` +b) `git add` +c) `git commit` +d) `git push` + +## Submission +* Declare a variable called `answer` in *solution.py* and assign it to either 'a', 'b', 'c' or 'd'. diff --git a/introduction_and_environment/git/1_staging_area/Solution/solution.py b/introduction_and_environment/git/1_staging_area/Solution/solution.py new file mode 100644 index 0000000..cccdee2 --- /dev/null +++ b/introduction_and_environment/git/1_staging_area/Solution/solution.py @@ -0,0 +1,2 @@ +# Code your solution here +answer = '' diff --git a/introduction_and_environment/git/1_staging_area/Solution/test_solution.py b/introduction_and_environment/git/1_staging_area/Solution/test_solution.py new file mode 100644 index 0000000..f632b37 --- /dev/null +++ b/introduction_and_environment/git/1_staging_area/Solution/test_solution.py @@ -0,0 +1,5 @@ + +def test_solution(): + import solution + assert solution.answer in {'c', 'C'} + diff --git a/introduction_and_environment/git/1_update_code/README.md b/introduction_and_environment/git/1_update_code/README.md new file mode 100644 index 0000000..994da9e --- /dev/null +++ b/introduction_and_environment/git/1_update_code/README.md @@ -0,0 +1,12 @@ +# Updating Code + +## Problem Description +Which of the following pushes changes from your working directory to your staging area? + +a) `git init` +b) `git add` +c) `git commit` +d) `git push` + +## Submission +* Declare a variable called `answer` in *solution.py* and assign it to either 'a', 'b', 'c' or 'd'. diff --git a/introduction_and_environment/git/1_update_code/Solution/solution.py b/introduction_and_environment/git/1_update_code/Solution/solution.py new file mode 100644 index 0000000..cccdee2 --- /dev/null +++ b/introduction_and_environment/git/1_update_code/Solution/solution.py @@ -0,0 +1,2 @@ +# Code your solution here +answer = '' diff --git a/introduction_and_environment/git/1_update_code/Solution/test_solution.py b/introduction_and_environment/git/1_update_code/Solution/test_solution.py new file mode 100644 index 0000000..6e6e451 --- /dev/null +++ b/introduction_and_environment/git/1_update_code/Solution/test_solution.py @@ -0,0 +1,5 @@ + +def test_solution(): + import solution + assert solution.answer in {'b', 'B'} + diff --git a/introduction_and_environment/git/README.md b/introduction_and_environment/git/README.md index 9ffc8a7..b0fc232 100644 --- a/introduction_and_environment/git/README.md +++ b/introduction_and_environment/git/README.md @@ -1 +1,8 @@ -# Git exercises +# Exercises for Git + +| **Exercise ID** | **Exercise** | +|:---------------:|:-------------------:| +| easy_e1 | [Staging Area](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/git/easy_e1) | +| easy_e2 | [Remote Repo](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/git/easy_e2) | +| easy_e3 | [Updating Code](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/git/easy_e3) | +| easy_e4 | [Creating a Repository](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/git/easy_e4) | diff --git a/introduction_and_environment/hello_world/1_arithmetic/README.md b/introduction_and_environment/hello_world/1_arithmetic/README.md index 57445e4..5df48af 100644 --- a/introduction_and_environment/hello_world/1_arithmetic/README.md +++ b/introduction_and_environment/hello_world/1_arithmetic/README.md @@ -1,9 +1,9 @@ # Arithmetic ## Problem Description -The *soluyion.py* file contains 2 integers `x` and `y` whos contents is hidden from you (The default values of 0 are placeholders). Below is a table of 10 names you must create and the associated values they should be bound to. +The *solution.py* file contains 2 variables `x` and `y` whose contents are hidden from you (the default values of 0 are placeholders). Below is a table of 7 variables you must create and the associated values they should be bound to. - Name | Value + Variable | Value :----------:|:-----: `SUM` | `x + y` `DIFF` | `x - y` @@ -14,7 +14,7 @@ The *soluyion.py* file contains 2 integers `x` and `y` whos contents is hidden f `REMAINDER` | `x % y` ## Testing -* To test your solution, type 'pytest' within the **Solutions** subdirectory +* To test your solution, type 'pytest' within the **solution** subdirectory ## Submission -* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory +* Submit your answers in the *solution.py* file within the *solution* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/1_concantenation/README.md b/introduction_and_environment/hello_world/1_concantenation/README.md new file mode 100644 index 0000000..fd863ad --- /dev/null +++ b/introduction_and_environment/hello_world/1_concantenation/README.md @@ -0,0 +1,15 @@ +## Concatenate Data + +## Motivation +Python allows the developer to concatenate a string with another string but never with the integer/float data types. + +## Problem Description +Write a python script that contains 2 string variables: `string_1` and `string_2` + +Your goal is to concatenate the 2 variables and store the result inside another variable, `result`. + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py b/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/hello_world/1_concantenation/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/hello_world/1_concantenation/Solution/test_solution.py b/introduction_and_environment/hello_world/1_concantenation/Solution/test_solution.py new file mode 100644 index 0000000..5183bc0 --- /dev/null +++ b/introduction_and_environment/hello_world/1_concantenation/Solution/test_solution.py @@ -0,0 +1,16 @@ + + +def test_solution(monkeypatch): + # x="Good Morning " + # y="Universe" + # ret_val1=None + + # def g(num1): + # nonlocal ret_val1 + # ret_val1=num1 + + # monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.result == solution.string_1 + solution.string_2 + # assert solution.string_2==y diff --git a/introduction_and_environment/hello_world/1_name_bindings/README.md b/introduction_and_environment/hello_world/1_name_bindings/README.md index 1d1dc2a..847106e 100644 --- a/introduction_and_environment/hello_world/1_name_bindings/README.md +++ b/introduction_and_environment/hello_world/1_name_bindings/README.md @@ -1,10 +1,10 @@ # Name Bindings ## Problem Description -Declare 3 names in the *solution.py* file `x`, `y`, `z` which should the values `1337`, `'hello world'` and `13.5` respectively. +Declare 3 names in the *solution.py* file: `x`, `y`, `z` which should the values `1337`, `'hello world'` and `13.5` respectively. ## Testing -* To test your solution, type 'pytest' within the **Solutions** subdirectory +* To test your solution, type 'pytest' within the **solution** subdirectory ## Submission -* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory +* Submit your answers in the *solution.py* file within the *solution* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py b/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py index a57ccc8..b8f3971 100644 --- a/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py +++ b/introduction_and_environment/hello_world/1_name_bindings/solution/solution.py @@ -1,3 +1,3 @@ x = 1337 -y = 'hello world' +y = "hello world" z = 13.5 diff --git a/introduction_and_environment/hello_world/1_operators/README.md b/introduction_and_environment/hello_world/1_operators/README.md index 6da07c0..05138c2 100644 --- a/introduction_and_environment/hello_world/1_operators/README.md +++ b/introduction_and_environment/hello_world/1_operators/README.md @@ -1,10 +1,10 @@ # Operators ## Problem Description -Python provides us with `//` and `%` operators for integer types. Determine 2 integers `X` and `Y` such that `X % Y` equals `X // Y`. Store these numbers in their respective names. +Python provides us with `//` and `%` operators for integer types. Determine 2 integers `x` and `y` such that `x % y` equals `x // y`. Store these numbers in their respective names. ## Testing -* To test your solution, type 'pytest' within the **Solutions** subdirectory +* To test your solution, type 'pytest' within the **solution** subdirectory ## Submission -* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory +* Submit your answers in the *solution.py* file within the *solution* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/1_operators/solution/test_solution.py b/introduction_and_environment/hello_world/1_operators/solution/test_solution.py index 39eeca8..77a35f8 100644 --- a/introduction_and_environment/hello_world/1_operators/solution/test_solution.py +++ b/introduction_and_environment/hello_world/1_operators/solution/test_solution.py @@ -1,4 +1,4 @@ import solution def test_solution(): - assert solution.X % solution.Y == solution.X // solution.Y + assert solution.x % solution.y == solution.x // solution.y diff --git a/introduction_and_environment/hello_world/2_capture_display/README.md b/introduction_and_environment/hello_world/2_capture_display/README.md new file mode 100644 index 0000000..5ed48f8 --- /dev/null +++ b/introduction_and_environment/hello_world/2_capture_display/README.md @@ -0,0 +1,15 @@ +# Capture Display + +## Motivation +Python provides us with the input() keyword in order to capture data from the user. + +## Problem Description +Write a Python script that asks the user for name and age . Store these values in `name`, `age` objects respectively. + +Print the values. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/2_capture_display/Solution/__pycache__/solution.cpython-37.pyc b/introduction_and_environment/hello_world/2_capture_display/Solution/__pycache__/solution.cpython-37.pyc new file mode 100644 index 0000000..c0d7828 Binary files /dev/null and b/introduction_and_environment/hello_world/2_capture_display/Solution/__pycache__/solution.cpython-37.pyc differ diff --git a/introduction_and_environment/hello_world/2_capture_display/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc b/introduction_and_environment/hello_world/2_capture_display/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc new file mode 100644 index 0000000..93b0d49 Binary files /dev/null and b/introduction_and_environment/hello_world/2_capture_display/Solution/__pycache__/test_solution.cpython-37-pytest-5.3.5.pyc differ diff --git a/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/hello_world/2_capture_display/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/hello_world/2_capture_display/Solution/test_solution.py b/introduction_and_environment/hello_world/2_capture_display/Solution/test_solution.py new file mode 100644 index 0000000..8ea7237 --- /dev/null +++ b/introduction_and_environment/hello_world/2_capture_display/Solution/test_solution.py @@ -0,0 +1,24 @@ + +def test_solution(monkeypatch): + x = ['Charlie','100'] + index = -1 + ret_val1 = None + ret_val2 = None + + def f(): + nonlocal index + nonlocal x + index += 1 + return x[index] + + def g(num1,num2): + nonlocal ret_val1 + nonlocal ret_val2 + ret_val1 = num1 + ret_val2 = num2 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + import solution + assert solution.name == 'Charlie' + assert solution.age == '100' diff --git a/introduction_and_environment/hello_world/2_python_caches/README.md b/introduction_and_environment/hello_world/2_python_caches/README.md index 03ce80e..4960001 100644 --- a/introduction_and_environment/hello_world/2_python_caches/README.md +++ b/introduction_and_environment/hello_world/2_python_caches/README.md @@ -27,9 +27,9 @@ Your goal is to determine what range of integers Python saves in memory (caches) * b) What is the upper bound of the range? ## Testing -* To test your solution, type 'pytest' within the **Solutions** subdirectory +* To test your solution, type 'pytest' within the **solution** subdirectory ## Submission -* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory -* The file contains 2 variables - `LOWER_BOUND` and `UPPER_BOUND representing each bound respectively +* Submit your answers in the *solution.py* file within the *solution* subdirectory within this directory +* The file contains 2 variables - `LOWER_BOUND` and `UPPER_BOUND` representing each bound respectively * Overwrite these numbers with your answers diff --git a/introduction_and_environment/hello_world/2_python_caches/solution/solution.py b/introduction_and_environment/hello_world/2_python_caches/solution/solution.py index 3e9db70..45a087b 100644 --- a/introduction_and_environment/hello_world/2_python_caches/solution/solution.py +++ b/introduction_and_environment/hello_world/2_python_caches/solution/solution.py @@ -1,2 +1,2 @@ -LOWER_BOUND = -5 -UPPER_BOUND = 256 +LOWER_BOUND = 0 +UPPER_BOUND = 0 diff --git a/introduction_and_environment/hello_world/2_string_arithmetic/README.md b/introduction_and_environment/hello_world/2_string_arithmetic/README.md index 7e891a9..580e2d5 100644 --- a/introduction_and_environment/hello_world/2_string_arithmetic/README.md +++ b/introduction_and_environment/hello_world/2_string_arithmetic/README.md @@ -9,7 +9,7 @@ Determine how many of the 7 operators listed above work on the `str` type and st Hint: Don't just try arithmetic with strings and strings, try arithmetic with strings and integers as well ## Testing -* To test your solution, type 'pytest' within the **Solutions** subdirectory +* To test your solution, type 'pytest' within the **solution** subdirectory ## Submission -* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory +* Submit your answers in the *solution.py* file within the *solution* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/2_string_duplication/README.md b/introduction_and_environment/hello_world/2_string_duplication/README.md new file mode 100644 index 0000000..79ad5e2 --- /dev/null +++ b/introduction_and_environment/hello_world/2_string_duplication/README.md @@ -0,0 +1,15 @@ +# String Duplicate + +## Motivation +String values can be duplicated with help of the * operator. + +## Problem Description +Write a Python script that asks the user for a string value and an intger value for number of times the user wishs to duplicate the string. +Store the values in `string_1` and `dup_val ` objects respectively. Store the result in variable `data`. +Print the result. + +## Testing +*done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py b/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/hello_world/2_string_duplication/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/hello_world/2_string_duplication/Solution/test_solution.py b/introduction_and_environment/hello_world/2_string_duplication/Solution/test_solution.py new file mode 100644 index 0000000..a4e082c --- /dev/null +++ b/introduction_and_environment/hello_world/2_string_duplication/Solution/test_solution.py @@ -0,0 +1,24 @@ + + +def test_solution(monkeypatch): + x=['Charlie',5] + index=-1 + ret_val= None + + def f(): + nonlocal x + nonlocal index + index+=1 + return x[index] + + def g(num): + nonlocal ret_val + ret_val=num + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.string_1=='Charlie' + assert solution.dup_val==5 + diff --git a/introduction_and_environment/hello_world/2_type_check/README.md b/introduction_and_environment/hello_world/2_type_check/README.md new file mode 100644 index 0000000..fc73075 --- /dev/null +++ b/introduction_and_environment/hello_world/2_type_check/README.md @@ -0,0 +1,17 @@ +# Type Check + +## Motivation +Python provides us with the type() function to capture and check the data type of a value from the user. +STANDARD DATA TYPES: 1.Integer 2.Float 3.String 4.Boolean 5.Complex Number + +## Problem Description +Write a Python script that asks the user to input any 2 values. +Store the values in `input_1` and `input_2 ` objects respectively. Check the type of each input and store the results in the variable names `data_1` and `data_2`. +Print the result. + + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/2_type_check/Solution/solution.py b/introduction_and_environment/hello_world/2_type_check/Solution/solution.py new file mode 100644 index 0000000..0ec5aa4 --- /dev/null +++ b/introduction_and_environment/hello_world/2_type_check/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here... diff --git a/introduction_and_environment/hello_world/2_type_check/Solution/test_solution.py b/introduction_and_environment/hello_world/2_type_check/Solution/test_solution.py new file mode 100644 index 0000000..c3eb76a --- /dev/null +++ b/introduction_and_environment/hello_world/2_type_check/Solution/test_solution.py @@ -0,0 +1,26 @@ + + +def test_solution(monkeypatch): + x=[1,2.0] + index = -1 + ret_val1= None + ret_val2= None + + def f(): + nonlocal index + nonlocal x + index += 1 + return x[index] + + def g(num1,num2): + nonlocal ret_val1 + nonlocal ret_val2 + ret_val1=num1 + ret_val2=num2 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.input_1==1 + assert solution.input_2==2.0 diff --git a/introduction_and_environment/hello_world/3_type_change/README.md b/introduction_and_environment/hello_world/3_type_change/README.md new file mode 100644 index 0000000..821f742 --- /dev/null +++ b/introduction_and_environment/hello_world/3_type_change/README.md @@ -0,0 +1,13 @@ +# Type Change + +## Problem Description +The type() method is key for changing data type of an object value. +Write a python script that contains 2 variables: `object_1` and `object_2`. They should contain a float and string value respectively. +Convert `object_1` into a string and `object_2` into an integer. +Print the final two values. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_and_environment/hello_world/3_type_change/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_and_environment/hello_world/3_type_change/Solution/test_solution.py b/introduction_and_environment/hello_world/3_type_change/Solution/test_solution.py new file mode 100644 index 0000000..4a90689 --- /dev/null +++ b/introduction_and_environment/hello_world/3_type_change/Solution/test_solution.py @@ -0,0 +1,18 @@ + +def test_solution(monkeypatch): + ret_val1= None + ret_val2=None + + def g(num1,num2): + nonlocal ret_val1 + nonlocal ret_val2 + ret_val1 = num1 + ret_val2 = num2 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert type(solution.object_1) == float + assert type(solution.object_2_ == str + assert type(ret_val1) == str + assert type(ret_val2) == int diff --git a/introduction_and_environment/hello_world/3_user_input/README.md b/introduction_and_environment/hello_world/3_user_input/README.md index 3259b35..4bcfe5c 100644 --- a/introduction_and_environment/hello_world/3_user_input/README.md +++ b/introduction_and_environment/hello_world/3_user_input/README.md @@ -1,10 +1,10 @@ # User Input ## Problem Description -Write a Python script in *solution.py* that asks the user for 3 numbers. Store these numbers in `FIRST_NUM`, `SECOND_NUM` and `THIRD_NUM` respectively. Then print the average of these 3 numbers. +Write a Python script in *solution.py* that asks the user for 3 inputs. Store these as integers with the variable names `FIRST_NUM`, `SECOND_NUM` and `THIRD_NUM` respectively. Then print the average of these 3 numbers. ## Testing -* To test your solution, type 'pytest' within the **Solutions** subdirectory +* To test your solution, type 'pytest' within the **solution** subdirectory ## Submission -* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory +* Submit your answers in the *solution.py* file within the *solution* subdirectory within this directory diff --git a/introduction_and_environment/hello_world/README.md b/introduction_and_environment/hello_world/README.md index 7e3057c..8d098ad 100644 --- a/introduction_and_environment/hello_world/README.md +++ b/introduction_and_environment/hello_world/README.md @@ -1,8 +1,16 @@ # Exercises for Hello World -* 1_Arithmetic -* 1_Name_Bindings -* 1_Operators -* 2_Python_Caches -* 2_String_Arithmetic -* 3_User_Input + +| Exercise ID | Exercise | +|:-----------:|:--------:| +| easy_e1 | [Arithmetic](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/1_arithmetic) | +| easy_e2 | [Concatenation](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/1_concantenation) | +| easy_e3 | [Name Bindings](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/1_name_bindings) | +| easy_e4 | [Operators](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/1_operators | +| medium_e1 | [Capture Display](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_capture_display) | +| medium_e2 | [Python Caches](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_python_caches) | +| medium_e3 | [String Arithmetic](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_string_arithmetic) | +| medium_e4 | [String Duplication](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_string_duplication) | +| medium_e5 | [Type Checking](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/2_type_check) | +| hard_e1 | [Type Change](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/3_type_change) | +| hard_e2 | [User Input](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_and_environment/hello_world/3_user_input) | diff --git a/introduction_and_environment/introduction_to_programming/1_DNS/README.md b/introduction_and_environment/introduction_to_programming/1_DNS/README.md new file mode 100644 index 0000000..0096769 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_DNS/README.md @@ -0,0 +1,20 @@ +# DNS + +## Motivation + + +## Problem Description +DNS in internet technology stands for + +a.Distributed Name System +b.Data Name System +c.Dynamic Name System +d.Domain Name System + +Your solution should `print` the correct answer (the line as it is written above, minus the letter choice and `.`) + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py new file mode 100644 index 0000000..ee95bbb --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_DNS/solution/solution.py @@ -0,0 +1 @@ +# Code your solution below \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_DNS/solution/test_solution.py b/introduction_and_environment/introduction_to_programming/1_DNS/solution/test_solution.py new file mode 100644 index 0000000..b9a42c7 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_DNS/solution/test_solution.py @@ -0,0 +1,16 @@ +import pytest + +ret_val= None + +def g(result): + global ret_val + ret_val = result + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution + + assert ret_val == "Domain Name System" + + diff --git a/introduction_and_environment/introduction_to_programming/1_architecture/README.md b/introduction_and_environment/introduction_to_programming/1_architecture/README.md new file mode 100644 index 0000000..fc2cefb --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_architecture/README.md @@ -0,0 +1,20 @@ +# Architecture + +## Motivation + + +## Problem Description +The basic architecture of the computer was developed by + +a. John Von Neumann +b. Charles Babbage +c. Blaise Pascal +d. Garden Moore + +Your solution should `print` the correct answer (the line as it is written above, minus the letter choice and `.`) + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py new file mode 100644 index 0000000..abe91ec --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_architecture/solution/solution.py @@ -0,0 +1 @@ +# Code your solution below diff --git a/introduction_and_environment/introduction_to_programming/1_architecture/solution/test_solution.py b/introduction_and_environment/introduction_to_programming/1_architecture/solution/test_solution.py new file mode 100644 index 0000000..c82012e --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_architecture/solution/test_solution.py @@ -0,0 +1,15 @@ +import pytest + +ret_val= None + +def g(result): + global ret_val + ret_val = result + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution + assert ret_val == "a.John Von Neuman" + + diff --git a/introduction_and_environment/introduction_to_programming/1_bytes/README.md b/introduction_and_environment/introduction_to_programming/1_bytes/README.md new file mode 100644 index 0000000..1791ecc --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_bytes/README.md @@ -0,0 +1,20 @@ +# Bytes + +## Motivation + + +## Problem Description +Which of the following is the largest unit of storage + +a.Gigabyte +b.Kilobyte +c.Megabyte +d.Terabyte + +Your solution should `print` the correct answer (the line as it is written above, minus the letter choice and `.`) + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py new file mode 100644 index 0000000..abe91ec --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_bytes/solution/solution.py @@ -0,0 +1 @@ +# Code your solution below diff --git a/introduction_and_environment/introduction_to_programming/1_bytes/solution/test_solution.py b/introduction_and_environment/introduction_to_programming/1_bytes/solution/test_solution.py new file mode 100644 index 0000000..657bd1c --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_bytes/solution/test_solution.py @@ -0,0 +1,16 @@ +import pytest + +ret_val= None + +def g(result): + global ret_val + ret_val = result + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution + + assert ret_val == "Gigabyte" + + diff --git a/introduction_and_environment/introduction_to_programming/1_languages/README.md b/introduction_and_environment/introduction_to_programming/1_languages/README.md new file mode 100644 index 0000000..c4b55af --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_languages/README.md @@ -0,0 +1,20 @@ +# Languages + +## Motivation + + +## Problem Description +A program that can execute high-level language programs. + +a) Compiler +b) Interpreter +c) Sensor +d) Circuitry + +Your solution should `print` the correct answer (the line as it is written above, minus the letter choice and `.`) + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py b/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py new file mode 100644 index 0000000..ee95bbb --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_languages/solution/solution.py @@ -0,0 +1 @@ +# Code your solution below \ No newline at end of file diff --git a/introduction_and_environment/introduction_to_programming/1_languages/solution/test_solution.py b/introduction_and_environment/introduction_to_programming/1_languages/solution/test_solution.py new file mode 100644 index 0000000..dab62de --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/1_languages/solution/test_solution.py @@ -0,0 +1,16 @@ +import pytest + +ret_val= None + +def g(result): + global ret_val + ret_val = result + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution + + assert ret_val == "Interpreter" + + diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/README.md b/introduction_and_environment/introduction_to_programming/2_ASCII/README.md new file mode 100644 index 0000000..9b4961a --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/README.md @@ -0,0 +1,20 @@ +# ASCII + +## Motivation + + +## Problem Description +Each byte of character is stored as its ASCII value in _______ + +a) Hexadecimal +b) Binary +c) Octal +d) Decimal + +Your solution should `print` the correct answer (the line as it is written above, minus the letter choice and `.`) + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/solution.py new file mode 100644 index 0000000..e69de29 diff --git a/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/test_solution.py b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/test_solution.py new file mode 100644 index 0000000..a51c7cc --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/2_ASCII/Solutions/test_solution.py @@ -0,0 +1,16 @@ +import pytest + +ret_val= None + +def g(result): + global ret_val + ret_val = result + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution + + assert ret_val == "Boolean" + + diff --git a/introduction_and_environment/introduction_to_programming/2_operators/README.md b/introduction_and_environment/introduction_to_programming/2_operators/README.md new file mode 100644 index 0000000..86b3c12 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/2_operators/README.md @@ -0,0 +1,20 @@ +# Operators + +## Motivation + + +## Problem Description +AND, OR and NOT are logical operators. What data type is expected for their operands? + + a) Integer + b) Boolean + c) Decimal + d) Character + +Your solution should `print` the correct answer (the line as it is written above, minus the letter choice and `.`) + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/solution.py new file mode 100644 index 0000000..e69de29 diff --git a/introduction_and_environment/introduction_to_programming/2_operators/Solutions/test_solution.py b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/test_solution.py new file mode 100644 index 0000000..49c4fde --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/2_operators/Solutions/test_solution.py @@ -0,0 +1,16 @@ +import pytest + +ret_val= None + +def g(result): + global ret_val + ret_val = result + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution + + assert ret_val == "Hexadecimal" + + diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/README.md b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/README.md new file mode 100644 index 0000000..989b4b3 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/README.md @@ -0,0 +1,19 @@ +# Bitwise Operators 1 + +## Motivation + + +## Problem Description +Given two binary values x and y, compute the following bitwise operations on them: + +1.Bitwise AND (&) +2.Bitwise OR (|) +3.Bitwise NOT (~) + +Return the solutions in objects `Answer_and`,`Answer_or` and `Answer_not` respectively and print the same. + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/solution.py new file mode 100644 index 0000000..e69de29 diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/test_solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/test_solution.py new file mode 100644 index 0000000..d179f96 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_1/Solutions/test_solution.py @@ -0,0 +1,27 @@ +import pytest + +ret_val_1= None +ret_val_2= None +ret_val_3= None + + +def g(x,x1,x2): + global ret_val_1 + global ret_val_2 + global ret_val_3 + ret_val_1 = x + ret_val_2 = x1 + ret_val_3 = x2 + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution + + assert ret_val_1 == bin(0b0) + assert ret_val_2 == bin(0b1110) + assert ret_val_3 == bin(-0b1001) + + + + diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/README.md b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/README.md new file mode 100644 index 0000000..e10aa29 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/README.md @@ -0,0 +1,19 @@ +# Bitwise Operators 2 + +## Motivation + + +## Problem Description +Given two binary values x and y, compute the following bitwise operations on that + +1.Bitwise XOR (^) +2.Bitwise right shift (>>) +3.Bitwise left Shift (<<) + +Return the solutions in objects `Answer_Xor`,`Answer_right_shift` and `Answer_left_shift` respectively and print the same. + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/solution.py new file mode 100644 index 0000000..e69de29 diff --git a/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/test_solution.py b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/test_solution.py new file mode 100644 index 0000000..105aa90 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/3_bitwise_operators_2/Solutions/test_solution.py @@ -0,0 +1,26 @@ +import pytest + +ret_val_1= None +ret_val_2= None +ret_val_3= None + +def g(x,x1,x2): + global ret_val_1 + global ret_val_2 + global ret_val_3 + ret_val_1 = x + ret_val_2 = x1 + ret_val_3 = x2 + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution as s + + assert ret_val_1 == bin(0b1110) + assert ret_val_2 == bin(0b11) + assert ret_val_3 == bin(0b1100) + + + + diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/README.md b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/README.md new file mode 100644 index 0000000..344e547 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/README.md @@ -0,0 +1,13 @@ +# Logical Operators 1 + +## Motivation + + +## Problem Description +Given `x`=`1` & `y`=`2` two values, apply logical operator `and`, by evaluating both the variables to `2` and return the boolean value. store the output in object `Answer`.print `Answer`. + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/solution.py new file mode 100644 index 0000000..e69de29 diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/test_solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/test_solution.py new file mode 100644 index 0000000..42cb8a6 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_1/Solutions/test_solution.py @@ -0,0 +1,18 @@ +import pytest + +ret_val_1= None + +def g(x): + global ret_val_1 + ret_val_1 = x + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution as s + + assert ret_val_1 == False + + + + diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/README.md b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/README.md new file mode 100644 index 0000000..954d6b9 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/README.md @@ -0,0 +1,13 @@ +# Logical Operators 2 + +## Motivation + + +## Problem Description +Given `x`=`1` & `y`=`2` two values, apply logical operator `and`, by evaluating both the variables to `2` and return the boolean value. store the output in object `Answer`.print `Answer`. + +## Testing +* To test your solution, type 'pytest' within the **solution** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/solution.py new file mode 100644 index 0000000..e69de29 diff --git a/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/test_solution.py b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/test_solution.py new file mode 100644 index 0000000..fc8bd68 --- /dev/null +++ b/introduction_and_environment/introduction_to_programming/3_logical_operators_2/Solutions/test_solution.py @@ -0,0 +1,18 @@ +import pytest + +ret_val_1= None + +def g(x): + global ret_val_1 + ret_val_1 = x + +def test_solution(monkeypatch): + monkeypatch.setattr('builtins.print',g) + + import solution as s + + assert ret_val_1 == True + + + + diff --git a/introduction_and_environment/introduction_to_programming/README.md b/introduction_and_environment/introduction_to_programming/README.md index e1a98c6..1eaff51 100644 --- a/introduction_and_environment/introduction_to_programming/README.md +++ b/introduction_and_environment/introduction_to_programming/README.md @@ -1,9 +1,15 @@ -# Introduction and Environment Exercises +# Introduction To Programming Exercises -* 1-Introduction-and-Environment-1 -* 1-Introduction-and-Environment-2 -* 1-Introduction-and-Environment-3 -* 2-Introduction-and-Environment-1 -* 2-Introduction-and-Environment-2 -* 3-Introduction-and-Environment-1 -* 3-Introduction-and-Environment-2 + +| Exercise ID | Exercise | +|:-----------:|:--------:| +| easy_e1 | [Architecture](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/1_architecture) | +| easy_e2 | [DNS](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/1_DNS) | +| easy_e3 | [Bytes](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/1_bytes) | +| easy_e4 | [Languages](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/1_languages) | +| medium_e1 | [ASCII](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/2_ASCII) | +| medium_e2 | [Operators](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/2_operators) | +| hard_e1 | [Logical Operators 1](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/3_logical_operators_1) | +| hard_e2 | [Logical Operators 2](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/3_logical_operators_2) | +| hard_e3 | [Bitwise Operators 1](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/3_bitwise_operators_1) | +| hard_e4 | [Bitwise Operators 2](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/introduction_to_programming/3_bitwise_operators_2) | diff --git a/introduction_and_environment/unix_and_bash/1_basic_commands/README.md b/introduction_and_environment/unix_and_bash/1_basic_commands/README.md new file mode 100644 index 0000000..f193339 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_basic_commands/README.md @@ -0,0 +1,40 @@ +# Command Basics + +## Problem Description +The list below contains a number of variable names, as well as a text description of many different **bash** commands. Assign the name of the correct **bash** command, as a lowercase Python string, to each corresponding variable. + +Unnecessary spaces will result in failed tests, make sure not to leave trailing spaces in the solutions! + +For example: +Variable: `ONE` +Description: command used when you remember the name of a **bash** command, but forget what it does + +In *solution.py* you would write: +```python +ONE = 'man' +``` + +Variable: `TWO` +Description: View the contents of a directory + +Variable: `THREE` +Description: Create a new directory (ignore any necessary arguments or options) + +Variable: `FOUR` +Description: Create an empty file + +Variable: `FIVE` +Description: Create a copy of a file, or with an option, copy the contents of a directory + +Variable: `SIX` +Description: Change the name of a file or directory + +Variable: `SEVEN` +Description: Delete a file, or with an additional option, a directory + + +## Testing +* to test your solution, type 'pytest' within the **solutions** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory in this directory diff --git a/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py new file mode 100644 index 0000000..a19ce0a --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/solution.py @@ -0,0 +1,10 @@ +# The first has been completed for you... +ONE = 'man' + +# Assign the correct strings below +TWO = '' +THREE = '' +FOUR = '' +FIVE = '' +SIX = '' +SEVEN = '' diff --git a/introduction_and_environment/unix_and_bash/1_basic_commands/solution/test_solution.py b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/test_solution.py new file mode 100644 index 0000000..3b83648 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_basic_commands/solution/test_solution.py @@ -0,0 +1,14 @@ +import solution +from hashlib import sha1 + +def test_solution(): + def hashed_output(submission): + return sha1(submission.encode()).hexdigest() + + assert hashed_output(solution.ONE) == '8175e3c8753aeb1696959f72ede260ebf3ea14c5' + assert hashed_output(solution.TWO) == 'ebfdec641529d4b59a54e18f8b0e9730f85939fb' + assert hashed_output(solution.THREE) == '90868ffdfa3a8bd99cfa9f642349e60cf84e057a' + assert hashed_output(solution.FOUR) == 'f4d1f0193879cba82d65c5752c4ba5cbb43a7188' + assert hashed_output(solution.FIVE) == '3f81e91d69a8a61ffbf19297eb0791ad54ce5690' + assert hashed_output(solution.SIX) == '362d60cb3f6f8e96c37edac670b7618963233e07' + assert hashed_output(solution.SEVEN) == '5cd7e29c88170aa3f16281e0dbf5772c137f6d8d' diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options/README.md b/introduction_and_environment/unix_and_bash/1_commands_with_options/README.md new file mode 100644 index 0000000..3fe9b7f --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options/README.md @@ -0,0 +1,42 @@ +# Command Basics 2 + +## Problem Description +The list below contains a number of variable names, as well as a text description of many different **bash** commands. Assign the name of the correct **bash** command, as a lowercase Python string, to each corresponding variable. These are harder than the first few, as they may contain additional arguments to be included with the command name. + +Unnecessary spaces will result in failed tests, make sure not to leave trailing spaces in the solutions! + +For example: +Variable: `ONE` +Description: Command used when you remember the name of a **bash** command named "test", but forget what it does + +In *solution.py* you would write: +```python +ONE = 'man test' +``` + +Variable: `ONE` +Description: Navigate from the current directory to a new directory, named "exercises" + +Variable: `TWO` +Description: View our terminal's current directory location + +Variable: `THREE` +Description: View the *entire* contents of a file named "textfile.txt" in our terminal + +Variable: `FOUR` +Description: View *only* the last 10 lines of a file named "textfile.txt" + +Variable: `FIVE` +Description: View the contents of the current directory, including hidden files + +Variable: `SIX` +Description: View *only* the first 10 lines of a file named "textfile.txt" + +Variable: `SEVEN` +Description: Create a copy of a file, named "stackdata.json" with the name "stockdata.json + +## Testing +* to test your solution, type 'pytest' within the **solutions** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory in this directory diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py new file mode 100644 index 0000000..fa9fd39 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/solution.py @@ -0,0 +1,9 @@ +# Assign the correct strings below + +ONE = '' +TWO = '' +THREE = '' +FOUR = '' +FIVE = '' +SIX = '' +SEVEN = '' diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/test_solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/test_solution.py new file mode 100644 index 0000000..8a52666 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options/solution/test_solution.py @@ -0,0 +1,14 @@ +import solution +from hashlib import sha1 + +def test_solution(): + def hashed_output(submission): + return sha1(submission.encode()).hexdigest() + + assert hashed_output(solution.ONE) == '8f7096f862f1c01437d435b1440612fc5907d76c' + assert hashed_output(solution.TWO) == '37fa265330ad83eaa879efb1e2db6380896cf639' + assert hashed_output(solution.THREE) == 'aa2ba3db8235609f178bac463e31eb01c1a9e711' + assert hashed_output(solution.FOUR) == 'e52fb413040572fbc243c74e29760dd3c9867aea' + assert hashed_output(solution.FIVE) == 'fda17aa65051cb574d5f9f1cc4c7f3ddbc931735' + assert hashed_output(solution.SIX) == '3441d7e6e51f18f214ae7f2ca9c6a87fe14deea8' + assert hashed_output(solution.SEVEN) == 'e120eb80c4d1bc2976a2176f8dd83d0a795725b6' diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/README.md b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/README.md new file mode 100644 index 0000000..784b043 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/README.md @@ -0,0 +1,39 @@ +# Command Basics 3 + +## Problem Description +The list below contains a number of variable names, as well as a text description of many different **bash** commands. Assign the name of the correct **bash** command, as a lowercase Python string, to each corresponding variable. These are harder than the first few, as they may contain additional arguments to be included with the command name. + +Unnecessary spaces will result in failed tests, make sure not to leave trailing spaces in the solutions! + +For example: +Variable: `ONE` +Description: Command used when you remember the name of a **bash** command named "test", but forget what it does + +In *solution.py* you would write: +```python +ONE = 'man test' +``` + +Variable: `ONE` +Description: Search the contents of a file named "book.txt" for occurrences of the pattern "elephant" + +Variable: `TWO` +Description: Move a file named "notes.txt" from the current directory to a directory named "newdir" + +Variable: `THREE` +Description: Search all files in a directory named "testdir" for the pattern "string" + +Variable: `FOUR` +Description: Delete an empty directory named "empty" + +Variable: `FIVE` +Description: Navigate to our user's home directory (regardless of name) + +Variable: `SIX` +Description: Delete a non-empty directory, named "Downloads", as well as all of its contents + +## Testing +* to test your solution, type 'pytest' within the **solutions** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory in this directory diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py new file mode 100644 index 0000000..fa9fd39 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/solution.py @@ -0,0 +1,9 @@ +# Assign the correct strings below + +ONE = '' +TWO = '' +THREE = '' +FOUR = '' +FIVE = '' +SIX = '' +SEVEN = '' diff --git a/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/test_solution.py b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/test_solution.py new file mode 100644 index 0000000..b4343a1 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_commands_with_options_2/solution/test_solution.py @@ -0,0 +1,13 @@ +import solution +from hashlib import sha1 + +def test_solution(): + def hashed_output(submission): + return sha1(submission.encode()).hexdigest() + + assert hashed_output(solution.ONE) == '1efc27c5f639a389de478c3d2572063bf0b303f0' + assert hashed_output(solution.TWO) == '649b0028d6ad29d4b0099e6cd227551c19e75c68' + assert hashed_output(solution.THREE) == '3c8f2856c8f42eb101b62632788173107a857a88' + assert hashed_output(solution.FOUR) == 'e6e017e01c6c83091049d013bfad653f3fb75d27' + assert hashed_output(solution.FIVE) == '034778198a045c1ed80be271cdd029b76874f6fc' + assert hashed_output(solution.SIX) == '2c98f52bc8dc4272160f7ee35acfff3aa3f63676' diff --git a/introduction_and_environment/unix_and_bash/1_more_commands/README.md b/introduction_and_environment/unix_and_bash/1_more_commands/README.md new file mode 100644 index 0000000..3fe9b7f --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_more_commands/README.md @@ -0,0 +1,42 @@ +# Command Basics 2 + +## Problem Description +The list below contains a number of variable names, as well as a text description of many different **bash** commands. Assign the name of the correct **bash** command, as a lowercase Python string, to each corresponding variable. These are harder than the first few, as they may contain additional arguments to be included with the command name. + +Unnecessary spaces will result in failed tests, make sure not to leave trailing spaces in the solutions! + +For example: +Variable: `ONE` +Description: Command used when you remember the name of a **bash** command named "test", but forget what it does + +In *solution.py* you would write: +```python +ONE = 'man test' +``` + +Variable: `ONE` +Description: Navigate from the current directory to a new directory, named "exercises" + +Variable: `TWO` +Description: View our terminal's current directory location + +Variable: `THREE` +Description: View the *entire* contents of a file named "textfile.txt" in our terminal + +Variable: `FOUR` +Description: View *only* the last 10 lines of a file named "textfile.txt" + +Variable: `FIVE` +Description: View the contents of the current directory, including hidden files + +Variable: `SIX` +Description: View *only* the first 10 lines of a file named "textfile.txt" + +Variable: `SEVEN` +Description: Create a copy of a file, named "stackdata.json" with the name "stockdata.json + +## Testing +* to test your solution, type 'pytest' within the **solutions** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory in this directory diff --git a/introduction_and_environment/unix_and_bash/1_more_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/1_more_commands/solution/solution.py new file mode 100644 index 0000000..fa9fd39 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_more_commands/solution/solution.py @@ -0,0 +1,9 @@ +# Assign the correct strings below + +ONE = '' +TWO = '' +THREE = '' +FOUR = '' +FIVE = '' +SIX = '' +SEVEN = '' diff --git a/introduction_and_environment/unix_and_bash/1_more_commands/solution/test_solution.py b/introduction_and_environment/unix_and_bash/1_more_commands/solution/test_solution.py new file mode 100644 index 0000000..8a52666 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/1_more_commands/solution/test_solution.py @@ -0,0 +1,14 @@ +import solution +from hashlib import sha1 + +def test_solution(): + def hashed_output(submission): + return sha1(submission.encode()).hexdigest() + + assert hashed_output(solution.ONE) == '8f7096f862f1c01437d435b1440612fc5907d76c' + assert hashed_output(solution.TWO) == '37fa265330ad83eaa879efb1e2db6380896cf639' + assert hashed_output(solution.THREE) == 'aa2ba3db8235609f178bac463e31eb01c1a9e711' + assert hashed_output(solution.FOUR) == 'e52fb413040572fbc243c74e29760dd3c9867aea' + assert hashed_output(solution.FIVE) == 'fda17aa65051cb574d5f9f1cc4c7f3ddbc931735' + assert hashed_output(solution.SIX) == '3441d7e6e51f18f214ae7f2ca9c6a87fe14deea8' + assert hashed_output(solution.SEVEN) == 'e120eb80c4d1bc2976a2176f8dd83d0a795725b6' diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/README.md b/introduction_and_environment/unix_and_bash/2_bash_commands/README.md new file mode 100644 index 0000000..784b043 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/README.md @@ -0,0 +1,39 @@ +# Command Basics 3 + +## Problem Description +The list below contains a number of variable names, as well as a text description of many different **bash** commands. Assign the name of the correct **bash** command, as a lowercase Python string, to each corresponding variable. These are harder than the first few, as they may contain additional arguments to be included with the command name. + +Unnecessary spaces will result in failed tests, make sure not to leave trailing spaces in the solutions! + +For example: +Variable: `ONE` +Description: Command used when you remember the name of a **bash** command named "test", but forget what it does + +In *solution.py* you would write: +```python +ONE = 'man test' +``` + +Variable: `ONE` +Description: Search the contents of a file named "book.txt" for occurrences of the pattern "elephant" + +Variable: `TWO` +Description: Move a file named "notes.txt" from the current directory to a directory named "newdir" + +Variable: `THREE` +Description: Search all files in a directory named "testdir" for the pattern "string" + +Variable: `FOUR` +Description: Delete an empty directory named "empty" + +Variable: `FIVE` +Description: Navigate to our user's home directory (regardless of name) + +Variable: `SIX` +Description: Delete a non-empty directory, named "Downloads", as well as all of its contents + +## Testing +* to test your solution, type 'pytest' within the **solutions** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory in this directory diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py new file mode 100644 index 0000000..fa9fd39 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/solution.py @@ -0,0 +1,9 @@ +# Assign the correct strings below + +ONE = '' +TWO = '' +THREE = '' +FOUR = '' +FIVE = '' +SIX = '' +SEVEN = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_commands/solution/test_solution.py b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/test_solution.py new file mode 100644 index 0000000..b4343a1 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_bash_commands/solution/test_solution.py @@ -0,0 +1,13 @@ +import solution +from hashlib import sha1 + +def test_solution(): + def hashed_output(submission): + return sha1(submission.encode()).hexdigest() + + assert hashed_output(solution.ONE) == '1efc27c5f639a389de478c3d2572063bf0b303f0' + assert hashed_output(solution.TWO) == '649b0028d6ad29d4b0099e6cd227551c19e75c68' + assert hashed_output(solution.THREE) == '3c8f2856c8f42eb101b62632788173107a857a88' + assert hashed_output(solution.FOUR) == 'e6e017e01c6c83091049d013bfad653f3fb75d27' + assert hashed_output(solution.FIVE) == '034778198a045c1ed80be271cdd029b76874f6fc' + assert hashed_output(solution.SIX) == '2c98f52bc8dc4272160f7ee35acfff3aa3f63676' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/README.md b/introduction_and_environment/unix_and_bash/2_bash_operators/README.md new file mode 100644 index 0000000..3e7b4f0 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/README.md @@ -0,0 +1,36 @@ +# Bash Operators + +## Problem Description +The list below contains a number of variable names, as well as a text description of many different **bash** commands and operators that must be used. Assign the name of the correct **bash** command, as a lowercase Python string, to each corresponding variable. These are harder than the first few, and may need bash operators to pass data between commands or alter execution. + +Unnecessary spaces will result in failed tests, make sure not to leave trailing spaces in the solutions! + +For example: +Variable: `ONE` +Description: Commands to list the contents of a directory, and then search that output for any files ending in ".py" + +In *solution.py* you would write: +```python +ONE = 'ls | grep .py' +``` + +Variable: `ONE` +Description: Commands to create a directory named "testdir" and then navigate into that directory, if creation was successful + +Variable: `TWO` +Description: Commands to view the entire contents of a file named "textfile.txt" and search that output for occurrences of the word "and" + +Variable: `THREE` +Description: Commands to view the contents of the current directory, and then *append* that output to an existing text file named "contents.txt" + +Variable: `FOUR` +Description: Commands to *either* navigate into a directory named "current", or, if that command failed, create the directory (but not bother with navigation afterwards) + +Variable: `FIVE` +Description: Commands to view our command line's current directory path, and then write that output to a *new* file called "current_path.txt" + +## Testing +* to test your solution, type 'pytest' within the **solutions** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory in this directory diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py new file mode 100644 index 0000000..f34e86b --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/solution.py @@ -0,0 +1,7 @@ + +# Assign the correct strings below +ONE = '' +TWO = '' +THREE = '' +FOUR = '' +FIVE = '' diff --git a/introduction_and_environment/unix_and_bash/2_bash_operators/solution/test_solution.py b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/test_solution.py new file mode 100644 index 0000000..510d955 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_bash_operators/solution/test_solution.py @@ -0,0 +1,12 @@ +import solution +from hashlib import sha1 + +def test_solution(): + def hashed_output(submission): + return sha1(submission.encode()).hexdigest() + + assert hashed_output(solution.ONE) == '8d90393573522285c5d58b437885ccbb9a9daced' + assert hashed_output(solution.TWO) == '6862d5dbed79ab65cf70e169232ad10ea4575373' + assert hashed_output(solution.THREE) == 'a0d69d758be9fd8be90f83bb3c51c3539c105bdf' + assert hashed_output(solution.FOUR) == 'e31d24b0d08a712dd0c8155c15259958e43dcd04' + assert hashed_output(solution.FIVE) == 'd07f1559dea4f7fb83c1a2b0c506646542856acb' diff --git a/introduction_and_environment/unix_and_bash/2_intermediate_commands/README.md b/introduction_and_environment/unix_and_bash/2_intermediate_commands/README.md new file mode 100644 index 0000000..3e7b4f0 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_intermediate_commands/README.md @@ -0,0 +1,36 @@ +# Bash Operators + +## Problem Description +The list below contains a number of variable names, as well as a text description of many different **bash** commands and operators that must be used. Assign the name of the correct **bash** command, as a lowercase Python string, to each corresponding variable. These are harder than the first few, and may need bash operators to pass data between commands or alter execution. + +Unnecessary spaces will result in failed tests, make sure not to leave trailing spaces in the solutions! + +For example: +Variable: `ONE` +Description: Commands to list the contents of a directory, and then search that output for any files ending in ".py" + +In *solution.py* you would write: +```python +ONE = 'ls | grep .py' +``` + +Variable: `ONE` +Description: Commands to create a directory named "testdir" and then navigate into that directory, if creation was successful + +Variable: `TWO` +Description: Commands to view the entire contents of a file named "textfile.txt" and search that output for occurrences of the word "and" + +Variable: `THREE` +Description: Commands to view the contents of the current directory, and then *append* that output to an existing text file named "contents.txt" + +Variable: `FOUR` +Description: Commands to *either* navigate into a directory named "current", or, if that command failed, create the directory (but not bother with navigation afterwards) + +Variable: `FIVE` +Description: Commands to view our command line's current directory path, and then write that output to a *new* file called "current_path.txt" + +## Testing +* to test your solution, type 'pytest' within the **solutions** subdirectory + +## Submission +* Submit your answers in the *solution.py* file within the *solution* subdirectory in this directory diff --git a/introduction_and_environment/unix_and_bash/2_intermediate_commands/solution/solution.py b/introduction_and_environment/unix_and_bash/2_intermediate_commands/solution/solution.py new file mode 100644 index 0000000..f34e86b --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_intermediate_commands/solution/solution.py @@ -0,0 +1,7 @@ + +# Assign the correct strings below +ONE = '' +TWO = '' +THREE = '' +FOUR = '' +FIVE = '' diff --git a/introduction_and_environment/unix_and_bash/2_intermediate_commands/solution/test_solution.py b/introduction_and_environment/unix_and_bash/2_intermediate_commands/solution/test_solution.py new file mode 100644 index 0000000..510d955 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/2_intermediate_commands/solution/test_solution.py @@ -0,0 +1,12 @@ +import solution +from hashlib import sha1 + +def test_solution(): + def hashed_output(submission): + return sha1(submission.encode()).hexdigest() + + assert hashed_output(solution.ONE) == '8d90393573522285c5d58b437885ccbb9a9daced' + assert hashed_output(solution.TWO) == '6862d5dbed79ab65cf70e169232ad10ea4575373' + assert hashed_output(solution.THREE) == 'a0d69d758be9fd8be90f83bb3c51c3539c105bdf' + assert hashed_output(solution.FOUR) == 'e31d24b0d08a712dd0c8155c15259958e43dcd04' + assert hashed_output(solution.FIVE) == 'd07f1559dea4f7fb83c1a2b0c506646542856acb' diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/README.md b/introduction_and_environment/unix_and_bash/3_star_wars/README.md new file mode 100644 index 0000000..d096b65 --- /dev/null +++ b/introduction_and_environment/unix_and_bash/3_star_wars/README.md @@ -0,0 +1,49 @@ +# Command Line Workflow: Star Wars + +## Spoilers: Star Wars Episode IV: A New Hope +* This exercise contains spoilers for the 1977 film Star Wars (retitled as "Star Wars: Episode IV: A New Hope). While it has been over four decades, you have been warned. + +## Problem Description +* Navigating your computer through terminal is an extremely important, practically required skill to be a programmer. The following is an assignment where you will make / delete folders and files to help you get used to navigating your terminal and manipulating your files with bash commands. Perform all commands within the *solution* directory (there is no `solution.py` here, you'll be creating all necessary files.) + +### Use bash to perform the following commands, in order: +* Navigate into the "star_wars" folder +* Create a folder called "the_empire" +* Create a folder called "the_rebellion" +* Make the following folders + * "tatooine" + * "millenium_falcon" + * "death_star" + * "x_wing" + * "tie_fighter" +* Make the following text files (.txt) ***Make Sure to have the .txt extension on these files*** + * "luke_skywalker" + * "old_man_ben" + * "han_solo" + * "chewbacca" + * "leia_organa" + * "darth_vader" + * "emperor_palpatine" +* Open the darth_vader text file and add the text "Darth Vader" + * **Bonus points** if you add the text without opening the file +* Move the emperor and darth vader into the folder "the_empire" +* Move "luke_skywalker" and "old_man_ben" to the "tatooine" folder +* Luke has found out old man ben is actually Obi Wan Kenobi. Change the name of "old_man_ben" to "obi_wan_kenobi" +* Now they need to escape tatooine. Move "han_solo" and "chewbacca" into "tatooine" +* While all this is happening the Sith lords are sitting nice and cozy inside their giant metal moon. Move "darth_vader" and "emperor_palpatine" inside the "death_star" +* Back on tatooine the characters get on the fastest ship in the galaxy and take off to save the princess. Move all four files from tatooine into the millenium falcon +* The princess is also on the death star. Move "leia_organa" to the "death_star" +* Our heroes sneak onto the Death Star. Move all the files inside the "millenium_falcon" onto the "death_star" +* They found the princess! but in the process Obi Wan was struck down by Darth Vader. Delete the "obi_wan_kenobi" file +* Our other heroes retreat in anger. Move Luke, Leia, Han, and Chewbacca into the "millenium_falcon" +* Alright the rebels have regrouped and come up with a plan to destroy the death star. Luke gets into an x-wing to use his sweet piloting skills. Move "leia" into the "the_rebellion" directory. Move Luke into the "x_wing" +* Vader, also a legendary pilot, gets into the tie fighter to defend the death star. Move "darth_vader" out of the death_star and into the "tie_fighter" +* Luke uses those sweet farm boy desert skills and fires some torpedos into the core of the death star, destroying it. **CAREFULLY** Delete the folder "death_star" + * Remember that deletion of a directory is a high-stake operation + * **DO NOT** do this without checking your command for correctness + +## Testing +* to test your solution, type 'pytest' within the **solutions** subdirectory. It will use python to make sure your final directory/file structure is correct. + +## Submission +* Submit your answer in the *solution* subdirectory in this directory. Your "answer" will be the structure of the folders/files you created at the end of the exercise diff --git a/introduction_and_environment/unix_and_bash/3_star_wars/solution/test_solution.py b/introduction_and_environment/unix_and_bash/3_star_wars/solution/test_solution.py new file mode 100644 index 0000000..7c6b57f --- /dev/null +++ b/introduction_and_environment/unix_and_bash/3_star_wars/solution/test_solution.py @@ -0,0 +1,17 @@ +import os + +def test_solution(): + solution = {} + for dir_name, subdir_list, file_list in os.walk("star_wars"): + # dir_name, subdir_list, file_list = os.walk(".") + print(dir_name, subdir_list, file_list) + solution[dir_name] = file_list + + assert solution == {'star_wars': [], + 'star_wars/tatooine': [], + 'star_wars/tie_fighter': ['darth_vader.txt'], + 'star_wars/x_wing': ['luke_skywalker.txt'], + 'star_wars/millenium_falcon': ['han_solo.txt', 'chewbacca.txt'], + 'star_wars/the_rebellion': ['leia_organa.txt'], + 'star_wars/the_empire': [] + } diff --git a/introduction_and_environment/unix_and_bash/README.md b/introduction_and_environment/unix_and_bash/README.md index 024ba9e..57802c6 100644 --- a/introduction_and_environment/unix_and_bash/README.md +++ b/introduction_and_environment/unix_and_bash/README.md @@ -1,8 +1,9 @@ # Exercises for UNIX and Bash -* 1-UNIX-and-Bash1 -* 1-UNIX-and-Bash2 -* 1-UNIX-and-Bash3 -* 2-UNIX-and-Bash1 -* 2-UNIX-and-Bash2 -* 3-UNIX-and-Bash1 +| Exercise ID | Exercise | +|:-----------:|:--------:| +| easy_e1 | [Basic Commands](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/unix_and_bash/1_basic_commands) | +| easy_e2 | [Commands With Options](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/unix_and_bash/1_commands_with_options) | +| easy_e3 | [Commands With Options 2](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/unix_and_bash/1_commands_with_options_2) | +| medium_e1 | [Intermediate Commands](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/unix_and_bash/2_intermediate_commands) | +| hard_e1 | [Star Wars](https://github.com/ByteAcademyCo/Introduction-And-Environment/tree/master/exercises/unix_and_bash/3_star_wars) | diff --git a/introduction_to_python/README.md b/introduction_to_python/README.md index a837d8e..8309895 100644 --- a/introduction_to_python/README.md +++ b/introduction_to_python/README.md @@ -1,8 +1,9 @@ # Exercise Organization -## Exercise Sections -* Functions -* Recursion -* Classes -* Class Protocols -* MVC Architecture +| Section ID | Section Name | +|:-----------:|:--------:| +| 1 | [Functions](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_to_python/functions) | +| 2 | [Recursive Functions](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_to_python/recursion) | +| 3 | [Classes](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_to_python/classes) | +| 4 | [Class Protocols](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_to_python/class_protocols) | +| 5 | [MVC Architecture](https://github.com/ByteAcademyCo/Exercises/tree/master/introduction_to_python/mvc_architecture) | diff --git a/introduction_to_python/class_protocols/Protocols.md b/introduction_to_python/class_protocols/Protocols.md deleted file mode 100644 index 30040a4..0000000 --- a/introduction_to_python/class_protocols/Protocols.md +++ /dev/null @@ -1,50 +0,0 @@ -# Protocols - -* Create a class called Vector3D that is initalized with 3 integers - x, y, z -* The Vector3D class should support the following operations. For each operation, there is sample code that should pass - * Initialization - * Printing - * Airthmetic (Additon, Subtraction, Multiplication, Comparison) - * Iteration - -* Initialization -```Python -vec1 = Vector3D(1,2,3) -vec2 = Vector3D(9,8,7) -vec1.x == 1 -vec1.y == 2 -vec1.z == 3 -``` - -* Printing -```Python -print(vec1) == '(x = 1, y = 2, z = 3)' -print(vec2) == '(x = 9, y = 8, z = 7)' -``` - -* Addition, Subtraction -```Python -(vec1 + vec2).x == (vec1 + vec2).y == (vec1 + vec2).z -vec3 = vec1 - vec2 -vec3.x == -8 -vec3.y == -6 -vec3.z == -4 -``` - -* Multiplication ([Dot Product](https://en.wikipedia.org/wiki/Dot_product)) -```Python -vec1 * vec2 == 46 # (1*9 + 2*7 + 3*7 = 46) -``` - -* Comparison ([Magnitude](https://en.wikipedia.org/wiki/Magnitude_(mathematics)#Euclidean_vector_space)) -```Python -vec1 < vec2 == True -``` - -* Iteration - output x, y, z coordinates in that order -```Python -vec_diff = 0 -for i in vec1: - vec_diff -= i -vec_diff == -4 -``` diff --git a/introduction_to_python/functions/1-function1/Solution/solution.py b/introduction_to_python/functions/1-function1/Solution/solution.py deleted file mode 100644 index aa5bb66..0000000 --- a/introduction_to_python/functions/1-function1/Solution/solution.py +++ /dev/null @@ -1,10 +0,0 @@ -# Code your solution here -def ranger(number): - if number >=0 and number <=100: - data="Hooray, Falls in my range" - else: - data="Oops,outside range" - return data -number=int(input()) -result=ranger(number) -print(result) diff --git a/introduction_to_python/functions/1_default_args/README.md b/introduction_to_python/functions/1_default_args/README.md new file mode 100644 index 0000000..611cf29 --- /dev/null +++ b/introduction_to_python/functions/1_default_args/README.md @@ -0,0 +1,18 @@ +# Default Args + +## Motivation +Default keywords are used in function definition where each argument has a default value. + +Python allows us to update the default value from the function call. + +## Problem Description +Write a Python function that contains 2 default arguements of string type. +Your goal is concatenate the arguments and store the result in a variable `data`. +Create an object `result` and assign the output of the function call to it. +Print `result`. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/1_default_args/Solution/solution.py b/introduction_to_python/functions/1_default_args/Solution/solution.py new file mode 100644 index 0000000..b4981fe --- /dev/null +++ b/introduction_to_python/functions/1_default_args/Solution/solution.py @@ -0,0 +1,6 @@ +# Code your solution here +def create(val_1="Hello ",val_2="World"): + data=val_1+val_2 + return data +result=create() +print(result) \ No newline at end of file diff --git a/introduction_to_python/functions/1_default_args/Solution/test_solution.py b/introduction_to_python/functions/1_default_args/Solution/test_solution.py new file mode 100644 index 0000000..11562be --- /dev/null +++ b/introduction_to_python/functions/1_default_args/Solution/test_solution.py @@ -0,0 +1,13 @@ +def test_solution(monkeypatch): + ret_val1= None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + + + diff --git a/introduction_to_python/functions/1_function1/Solution/solution.py b/introduction_to_python/functions/1_function1/Solution/solution.py new file mode 100644 index 0000000..0e6d8cc --- /dev/null +++ b/introduction_to_python/functions/1_function1/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution heree diff --git a/introduction_to_python/functions/1-function1/Solution/test_solution.py b/introduction_to_python/functions/1_function1/Solution/test_solution.py similarity index 100% rename from introduction_to_python/functions/1-function1/Solution/test_solution.py rename to introduction_to_python/functions/1_function1/Solution/test_solution.py diff --git a/introduction_to_python/functions/1_range/README.md b/introduction_to_python/functions/1_range/README.md new file mode 100644 index 0000000..c6f8f6a --- /dev/null +++ b/introduction_to_python/functions/1_range/README.md @@ -0,0 +1,13 @@ +# Range + +## Problem Description +Write a Python function that asks the user for any integer value stored in object `number`. +Your goal is to check if that value is less than or equal to 100. If it is, return "GREATNESS"; otherwise, return "OOPS". +Create an variable `result` which performs function call to return data. +Print the data. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/1_range/Solution/solution.py b/introduction_to_python/functions/1_range/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/1_range/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/1_range/Solution/test_solution.py b/introduction_to_python/functions/1_range/Solution/test_solution.py new file mode 100644 index 0000000..c158e8b --- /dev/null +++ b/introduction_to_python/functions/1_range/Solution/test_solution.py @@ -0,0 +1,21 @@ +def test_solution(monkeypatch): + x=99 + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.number==x + + + + diff --git a/introduction_to_python/functions/1_return_hello/README.md b/introduction_to_python/functions/1_return_hello/README.md new file mode 100644 index 0000000..feddcdb --- /dev/null +++ b/introduction_to_python/functions/1_return_hello/README.md @@ -0,0 +1,16 @@ +# Return Hello + +## Motivation +Python function definition allows the developer to construct a block of code which performs certain functionality. + +## Problem Description +Write a Python function that asks the user for his/her name value stored in the variable `name`. +Your goal is to concatenate the prefix "Hello" to the object `name` and return it. +Create a variable `result` and store the result of the function call. +Print the data. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/1_return_hello/Solution/solution.py b/introduction_to_python/functions/1_return_hello/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/1_return_hello/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/1_return_hello/Solution/test_solution.py b/introduction_to_python/functions/1_return_hello/Solution/test_solution.py new file mode 100644 index 0000000..a5c4a82 --- /dev/null +++ b/introduction_to_python/functions/1_return_hello/Solution/test_solution.py @@ -0,0 +1,20 @@ +def test_solution(monkeypatch): + x='Newton' + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.name==x + + + diff --git a/introduction_to_python/functions/2_max_value/README.md b/introduction_to_python/functions/2_max_value/README.md new file mode 100644 index 0000000..7a0630d --- /dev/null +++ b/introduction_to_python/functions/2_max_value/README.md @@ -0,0 +1,17 @@ +# Max Value + +## Motivation +In Python every variable name is a reference. When we pass a variable to a function, a new reference to the object is created. + +## Problem Description +Write a Python function that asks the user for 3 integer values stored in `a`, `b` ,`c` respectively. +Your goal is to capture the 3 arguments, check which value is the maximum and store it in the variable name `max_value`. +Create a variable `result` and assign the output of the function to it. +Print the data. + + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/2_max_value/Solution/solution.py b/introduction_to_python/functions/2_max_value/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/2_max_value/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/2_max_value/Solution/test_solution.py b/introduction_to_python/functions/2_max_value/Solution/test_solution.py new file mode 100644 index 0000000..9c82a04 --- /dev/null +++ b/introduction_to_python/functions/2_max_value/Solution/test_solution.py @@ -0,0 +1,26 @@ +def test_solution(monkeypatch): + x=[1,2,3] + index=-1 + ret_val1= None + + def f(): + nonlocal x + nonlocal index + index+=1 + return x[index] + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.a==1 + assert solution.b==2 + assert solution.c==3 + + + + diff --git a/introduction_to_python/functions/2_shut_down/README.md b/introduction_to_python/functions/2_shut_down/README.md new file mode 100644 index 0000000..83248d7 --- /dev/null +++ b/introduction_to_python/functions/2_shut_down/README.md @@ -0,0 +1,20 @@ +# Shut Down + +## Motivation +Keyword arguments allow the caller of a function to specify argument names with values so that the caller does not need to remember the order of any parameters. + +Boolean type- `True`/ `False` + +## Problem Description +Write a Python function that asks the user for a boolean value stored in variable `x`. +Your goal is to check whether the variable is `True`-return "SHUTDOWN", otherwise return "SHUTDOWN ABORTED". sorted in variable `data`. +If the user enters any other value, the program must display an appropriate message. +Create a variable `result` and assign the output of the functionc all to it. +Print `result`. + + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/2_shut_down/Solution/solution.py b/introduction_to_python/functions/2_shut_down/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/2_shut_down/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/2_shut_down/Solution/test_solution.py b/introduction_to_python/functions/2_shut_down/Solution/test_solution.py new file mode 100644 index 0000000..14cb9e2 --- /dev/null +++ b/introduction_to_python/functions/2_shut_down/Solution/test_solution.py @@ -0,0 +1,20 @@ +def test_solution(monkeypatch): + y='true' + x='false' + ret_val1= None + + def f(): + nonlocal y + return y + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.x==y or solution.x==x + + diff --git a/introduction_to_python/functions/2_variable_argument/README.md b/introduction_to_python/functions/2_variable_argument/README.md new file mode 100644 index 0000000..f94a8ef --- /dev/null +++ b/introduction_to_python/functions/2_variable_argument/README.md @@ -0,0 +1,15 @@ +# Variable Arguments + +## Motivation +Variable length argument is a feature that allows a function to receive any number of arguments. There are situations where we want a function to handle variable number of arguments using (*args) (*Represented as a tuple) + +## Problem Description +Write a Python function that takes an variable length argument and return data. +Your goal is to create an object `result` which performs the function call by passing a series of string values, and then concatenating them all into one single string. +Print the output. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/2_variable_argument/Solution/solution.py b/introduction_to_python/functions/2_variable_argument/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/2_variable_argument/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/2_variable_argument/Solution/test_solution.py b/introduction_to_python/functions/2_variable_argument/Solution/test_solution.py new file mode 100644 index 0000000..1481bc5 --- /dev/null +++ b/introduction_to_python/functions/2_variable_argument/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + + + diff --git a/introduction_to_python/functions/3_anonymous/README.md b/introduction_to_python/functions/3_anonymous/README.md new file mode 100644 index 0000000..555b88c --- /dev/null +++ b/introduction_to_python/functions/3_anonymous/README.md @@ -0,0 +1,19 @@ +# Anonymous + +## Motivation +The **filter()** method filters the given sequence with the help of a function that tests each element in the sequence to be true or not. A **lambda** function is a single-line function declared with no name, which can have any number of arguments, but it can only have one expression + +## Problem Description +Write a python function that accepts an arbitrary number of positional arguments to find numbers divisible by thirteen from a list, using a lambda function. + +Your goal is to create a variable `result` will performs function call by passing a series of integer values. + +Use an anonymous function to filter and compare if divisible or not. + +Print the result. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/3_anonymous/Solution/solution.py b/introduction_to_python/functions/3_anonymous/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/3_anonymous/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/3_anonymous/Solution/test_solution.py b/introduction_to_python/functions/3_anonymous/Solution/test_solution.py new file mode 100644 index 0000000..1402dee --- /dev/null +++ b/introduction_to_python/functions/3_anonymous/Solution/test_solution.py @@ -0,0 +1,12 @@ +def test_solution(monkeypatch): + ret_val1= None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + + diff --git a/introduction_to_python/functions/3_count_even/README.md b/introduction_to_python/functions/3_count_even/README.md new file mode 100644 index 0000000..f304630 --- /dev/null +++ b/introduction_to_python/functions/3_count_even/README.md @@ -0,0 +1,14 @@ +# Count Even + +## Problem Description +Write a python function that accepts an arbitrary number of keyword arguments and figures out how many of its inputs are even. + +Your goal is to create a variable `result` which will perform the function call by passing a series of integer values. + +Print the number (total count) of elements in the input that are even. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/3_count_even/Solution/solution.py b/introduction_to_python/functions/3_count_even/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/3_count_even/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/3_count_even/Solution/test_solution.py b/introduction_to_python/functions/3_count_even/Solution/test_solution.py new file mode 100644 index 0000000..3c965af --- /dev/null +++ b/introduction_to_python/functions/3_count_even/Solution/test_solution.py @@ -0,0 +1,13 @@ +def test_solution(monkeypatch): + ret_val1= None + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + + + + diff --git a/introduction_to_python/functions/3_factorial/README.md b/introduction_to_python/functions/3_factorial/README.md new file mode 100644 index 0000000..00f5b00 --- /dev/null +++ b/introduction_to_python/functions/3_factorial/README.md @@ -0,0 +1,17 @@ +# Factorial + +## Motivation +The factorial, symbolized by an exclamation mark (!), is a quantity defined for all integers greater than or equal to 0. For an integer n greater than or equal to 1, the factorial is the product of all integers less than or equal to n but greater than or equal to 1. + +## Problem Description +Write a Python function that asks the user for 1 integer value stored in object `n`. +Your goal is to store the factorial of `n` in a new variable, `result`. +Print `result`. + +**DO NOT USE factorial() built in method** + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/3_factorial/Solution/solution.py b/introduction_to_python/functions/3_factorial/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/3_factorial/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/3_factorial/Solution/test_solution.py b/introduction_to_python/functions/3_factorial/Solution/test_solution.py new file mode 100644 index 0000000..70efea1 --- /dev/null +++ b/introduction_to_python/functions/3_factorial/Solution/test_solution.py @@ -0,0 +1,21 @@ +def test_solution(monkeypatch): + x=4 + ret_val1= None + + def f(): + nonlocal x + return x + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.input',f) + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.n==x + + + + diff --git a/introduction_to_python/functions/3_total/README.md b/introduction_to_python/functions/3_total/README.md new file mode 100644 index 0000000..4821d7a --- /dev/null +++ b/introduction_to_python/functions/3_total/README.md @@ -0,0 +1,17 @@ +# Total + +## Motivation +Compound data types have a collection of data. What if I need to return the total sum of my data? + +Built-in functions can help, but ***DO NOT USE SUM()*** for this exercise. + +## Problem Description +Write a Python function that takes one argument, a list (named `l`), and returns the sum of the list. + +Store the output of the function in a variable `result` and `print` it. + +## Testing +* done + +## Submission +* Submit your answers in the *solution.py* file within the *Solutions* subdirectory within this directory diff --git a/introduction_to_python/functions/3_total/Solution/solution.py b/introduction_to_python/functions/3_total/Solution/solution.py new file mode 100644 index 0000000..ade0317 --- /dev/null +++ b/introduction_to_python/functions/3_total/Solution/solution.py @@ -0,0 +1 @@ +# Code your solution here diff --git a/introduction_to_python/functions/3_total/Solution/test_solution.py b/introduction_to_python/functions/3_total/Solution/test_solution.py new file mode 100644 index 0000000..3ab61f2 --- /dev/null +++ b/introduction_to_python/functions/3_total/Solution/test_solution.py @@ -0,0 +1,14 @@ +def test_solution(monkeypatch): + x=[10,20,30,40,50,60] + ret_val1= None + + def g(num1): + nonlocal ret_val1 + ret_val1=num1 + + monkeypatch.setattr('builtins.print',g) + + import solution + assert solution.l==x + + diff --git a/introduction_to_python/functions/README.md b/introduction_to_python/functions/README.md index ed4156d..cc80019 100644 --- a/introduction_to_python/functions/README.md +++ b/introduction_to_python/functions/README.md @@ -1,8 +1,12 @@ # Exercises for Functions -* 1-functions1 -* 1-functions2 -* 1-functions3 -* 2-functions1 -* 2-functions2 -* 3-functions1 +* 1_default_args +* 1_range +* 1_return_hello +* 2_max_valule +* 2_shut_down +* 2_variable_arguments +* 3_anonymous +* 3_total +* 3_count_even +* 3_factorial diff --git a/introduction_to_python/object_oriented_programming/README.md b/introduction_to_python/object_oriented_programming/README.md new file mode 100644 index 0000000..e69de29 diff --git a/introduction_to_python/recursion/README.md b/introduction_to_python/recursion/README.md deleted file mode 100644 index 2a01e7d..0000000 --- a/introduction_to_python/recursion/README.md +++ /dev/null @@ -1,8 +0,0 @@ -# Exercises for Recursion - -* 1-recursion1 -* 1-recursion2 -* 1-recursion3 -* 2-recursion1 -* 2-recursion2 -* 3-recursion1 diff --git a/introduction_to_python/recursive_functions/1_array_sum/README.md b/introduction_to_python/recursive_functions/1_array_sum/README.md new file mode 100644 index 0000000..ffe3f85 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_array_sum/README.md @@ -0,0 +1,7 @@ +# Array_sum + +## Problem Description +Define a recursive Python function named `sum_array` that consumes one parameter `num_list` and returns the sum of the the numbers within the list. Do not use iteration of any form for this question. + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_to_python/recursive_functions/1_array_sum/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/1_array_sum/solutions/.model_solution/solution.py new file mode 100644 index 0000000..75b36d3 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_array_sum/solutions/.model_solution/solution.py @@ -0,0 +1,2 @@ +def sum_array(num_list): + return 0 if num_list == [] else num_list[0] + sum_array(num_list[1:]) diff --git a/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/1_array_sum/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/1_array_sum/solutions/test_solution.py b/introduction_to_python/recursive_functions/1_array_sum/solutions/test_solution.py new file mode 100644 index 0000000..3808d58 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_array_sum/solutions/test_solution.py @@ -0,0 +1,7 @@ +import solution + +def test_solution(monkeypatch): + assert solution.sum_array(num_list=[1,2,3]) == 6 + assert solution.sum_array(num_list=[1,-2,3.5]) == 2.5 + assert solution.sum_array(num_list=[]) == 0 + diff --git a/introduction_to_python/recursive_functions/1_count_down/README.md b/introduction_to_python/recursive_functions/1_count_down/README.md new file mode 100644 index 0000000..6166103 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_count_down/README.md @@ -0,0 +1,7 @@ +# Count Down + +## Problem Description +Define a recursive Python function named `count_down_from` that consumes one argument `num`. The function prints the numbers from `1` to `number` (inclusive) in descending order, one on each line. Do not use iteration of any form for this question. + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_to_python/recursive_functions/1_count_down/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/1_count_down/solutions/.model_solution/solution.py new file mode 100644 index 0000000..c275729 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_count_down/solutions/.model_solution/solution.py @@ -0,0 +1,4 @@ +def count_down_from(num): + print(num) + if num >= 1: + count_down_from(num-1) diff --git a/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py b/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/1_count_down/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/1_count_down/solutions/test_solution.py b/introduction_to_python/recursive_functions/1_count_down/solutions/test_solution.py new file mode 100644 index 0000000..0346565 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_count_down/solutions/test_solution.py @@ -0,0 +1,16 @@ +def test_solution(monkeypatch): + ret_val= [] + def g(num): + ret_val.append(num) + + monkeypatch.setattr('builtins.print',g) + + import solution + solution.count_down_from(3) + + assert ret_val[0] == 3 + assert ret_val[1] == 2 + assert ret_val[2] == 1 + assert len(ret_val) == 3 + + diff --git a/introduction_to_python/recursive_functions/1_find_power/README.md b/introduction_to_python/recursive_functions/1_find_power/README.md new file mode 100644 index 0000000..e1545d0 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_find_power/README.md @@ -0,0 +1,7 @@ +# Find Power + +## Problem Description +Define a recursive Python function named `power` that consumes two parameters `a` and `b`. The function returns `a` to the power of `b`. Do not use the `**` operator or iteration in this question. + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_to_python/recursive_functions/1_find_power/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/1_find_power/solutions/.model_solution/solution.py new file mode 100644 index 0000000..0fd195f --- /dev/null +++ b/introduction_to_python/recursive_functions/1_find_power/solutions/.model_solution/solution.py @@ -0,0 +1,9 @@ +def power(a,b): + if b==0: + return 1 + elif a==0: + return 0 + elif b==1: + return a + else: + return a*power(a,b-1) diff --git a/introduction_to_python/recursive_functions/1_find_power/solutions/solution.py b/introduction_to_python/recursive_functions/1_find_power/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/1_find_power/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/1_find_power/solutions/test_solution.py b/introduction_to_python/recursive_functions/1_find_power/solutions/test_solution.py new file mode 100644 index 0000000..dac3609 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_find_power/solutions/test_solution.py @@ -0,0 +1,6 @@ +def test_solution(): + import solution + assert solution.power(1,3) == 3 + assert solution.power(2,4) == 16 + assert solution.power(0,1) == 1 + assert solution.power(5,2) == 25 diff --git a/introduction_to_python/recursive_functions/1_reverse_string/README.md b/introduction_to_python/recursive_functions/1_reverse_string/README.md new file mode 100644 index 0000000..b4f9d73 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_reverse_string/README.md @@ -0,0 +1,7 @@ +# Reverse String + +## Problem Description +Define a recursive Python function named `reverse` that consumes one argument `string`. The function returns the a string whos contents is the reverse of `string` Do not use iteration of any form for this question. + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_to_python/recursive_functions/1_reverse_string/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/1_reverse_string/solutions/.model_solution/solution.py new file mode 100644 index 0000000..a5f9d06 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_reverse_string/solutions/.model_solution/solution.py @@ -0,0 +1,3 @@ +def reverse(string): + return '' if string is '' else reverse(string[1:]) + string[0] + diff --git a/introduction_to_python/recursive_functions/1_reverse_string/solutions/solution.py b/introduction_to_python/recursive_functions/1_reverse_string/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/1_reverse_string/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/1_reverse_string/solutions/test_solution.py b/introduction_to_python/recursive_functions/1_reverse_string/solutions/test_solution.py new file mode 100644 index 0000000..f0efd77 --- /dev/null +++ b/introduction_to_python/recursive_functions/1_reverse_string/solutions/test_solution.py @@ -0,0 +1,6 @@ +def test_solution(): + import solution + assert solution.reverse('hello') == 'oellh' + assert solution.reverse('') == '' + + diff --git a/introduction_to_python/recursive_functions/2_count_ways/README.md b/introduction_to_python/recursive_functions/2_count_ways/README.md new file mode 100644 index 0000000..ea1746a --- /dev/null +++ b/introduction_to_python/recursive_functions/2_count_ways/README.md @@ -0,0 +1,13 @@ +# Count ways + +## Problem Description +Assume you are climbing a stair case and it takes `n` steps to reach to the top. Each time you can either climb 1 or 2 steps. +Write a recursive Python function named `count_ways` that consumes a number `steps`. The function returns the number of distinct ways to climb to the top. Hint: Make sure you attempt the question before trying this one! + +* For Example +``` +countways(4) == 5 # (1, 1, 1, 1), (1, 1, 2), (2, 1, 1), (1, 2, 1), (2, 2) +``` +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory + diff --git a/introduction_to_python/recursive_functions/2_count_ways/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/2_count_ways/solutions/.model_solution/solution.py new file mode 100644 index 0000000..8cc28a1 --- /dev/null +++ b/introduction_to_python/recursive_functions/2_count_ways/solutions/.model_solution/solution.py @@ -0,0 +1,6 @@ +def fib(n): + return n if n <= 1 else fib(n-1) + fib(n-2) + +def count_ways(s): + return fib(s + 1) + diff --git a/introduction_to_python/recursive_functions/2_count_ways/solutions/solution.py b/introduction_to_python/recursive_functions/2_count_ways/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/2_count_ways/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/2_count_ways/solutions/test_solution.py b/introduction_to_python/recursive_functions/2_count_ways/solutions/test_solution.py new file mode 100644 index 0000000..281c338 --- /dev/null +++ b/introduction_to_python/recursive_functions/2_count_ways/solutions/test_solution.py @@ -0,0 +1,6 @@ +def test_solution(): + import solution + assert solution.count_ways(steps=2) == 2 + assert solution.count_ways(steps=10) == 89 + assert solution.count_ways(steps=20) == 10946 + diff --git a/introduction_to_python/recursive_functions/2_fibonacci/README.md b/introduction_to_python/recursive_functions/2_fibonacci/README.md new file mode 100644 index 0000000..95719f6 --- /dev/null +++ b/introduction_to_python/recursive_functions/2_fibonacci/README.md @@ -0,0 +1,7 @@ +# Fibonacci + +## Problem Description +Define a recursive Python function named `fibonacci` that consumes one argument `n`. The function returns the `n`th fibonacci number. To understand what a fibonacci number is, please reference [wikipedia](https://en.wikipedia.org/wiki/Fibonacci_number). Do not use iteration for this question. + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_to_python/recursive_functions/2_fibonacci/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/2_fibonacci/solutions/.model_solution/solution.py new file mode 100644 index 0000000..3dafdc0 --- /dev/null +++ b/introduction_to_python/recursive_functions/2_fibonacci/solutions/.model_solution/solution.py @@ -0,0 +1,8 @@ +def fibonacci(n): + if n < 0: + assert False + elif n in (1, 2): + return 1 + else: + return fibonacci(n-1)+fibonacci(n-2) + diff --git a/introduction_to_python/recursive_functions/2_fibonacci/solutions/solution.py b/introduction_to_python/recursive_functions/2_fibonacci/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/2_fibonacci/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/2_fibonacci/solutions/test_solution.py b/introduction_to_python/recursive_functions/2_fibonacci/solutions/test_solution.py new file mode 100644 index 0000000..c79cecd --- /dev/null +++ b/introduction_to_python/recursive_functions/2_fibonacci/solutions/test_solution.py @@ -0,0 +1,6 @@ +def test_solution(): + import solution + assert solution.fibonacci(n=5) == 5 + assert solution.fibonacci(n=10) == 55 + assert solution.fibonacci(n=15) == 610 + diff --git a/introduction_to_python/recursive_functions/2_find_factorial/README.md b/introduction_to_python/recursive_functions/2_find_factorial/README.md new file mode 100644 index 0000000..4b42cd3 --- /dev/null +++ b/introduction_to_python/recursive_functions/2_find_factorial/README.md @@ -0,0 +1,7 @@ +# Find Factorial + +## Problem Description +Define a recursive Python function named `factorial_recursive` that consumes a number `n` and returns the factorial of `n`. + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_to_python/recursive_functions/2_find_factorial/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/2_find_factorial/solutions/.model_solution/solution.py new file mode 100644 index 0000000..8777228 --- /dev/null +++ b/introduction_to_python/recursive_functions/2_find_factorial/solutions/.model_solution/solution.py @@ -0,0 +1,3 @@ +def factorial_recursive(n): + return 1 if n is 1 else n * factorial_recursive(n-1) + diff --git a/introduction_to_python/recursive_functions/2_find_factorial/solutions/solution.py b/introduction_to_python/recursive_functions/2_find_factorial/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/2_find_factorial/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/2_find_factorial/solutions/test_solution.py b/introduction_to_python/recursive_functions/2_find_factorial/solutions/test_solution.py new file mode 100644 index 0000000..886beda --- /dev/null +++ b/introduction_to_python/recursive_functions/2_find_factorial/solutions/test_solution.py @@ -0,0 +1,4 @@ +def test_solution(): + import solution + assert solution.factorial_recursive(5) == 120 + assert solution.factorial_recursive(10) == 3628800 diff --git a/introduction_to_python/recursive_functions/3_merge_sort/README.md b/introduction_to_python/recursive_functions/3_merge_sort/README.md new file mode 100644 index 0000000..b519b63 --- /dev/null +++ b/introduction_to_python/recursive_functions/3_merge_sort/README.md @@ -0,0 +1,13 @@ +# Merge Sort + +## Problem Description +Define a recursive Python function named `custom_sort` that consumes one argument `num_list`, a list of numbers. The function returns a new list containg the same numbers but in sorted order. Hint: Using the [Merge Sort](https://en.wikipedia.org/wiki/Merge_sort) algorithm is the most efficient way to solve this question. + +* For example +``` +custom_sort([1,6,3,9,0]) == [0,1,3,6,9] +``` + + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_to_python/recursive_functions/3_merge_sort/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/3_merge_sort/solutions/.model_solution/solution.py new file mode 100644 index 0000000..dd001d6 --- /dev/null +++ b/introduction_to_python/recursive_functions/3_merge_sort/solutions/.model_solution/solution.py @@ -0,0 +1,32 @@ +def merge_sort(num_list): + if len(num_list)>1: + mid = int(len(num_list)/2) + lefthalf = num_list[:mid] + righthalf = num_list[mid:] + + merge_sort(lefthalf) + merge_sort(righthalf) + + i=0 + j=0 + k=0 + + while i < len(lefthalf) and j < len(righthalf): + if lefthalf[i] < righthalf[j]: + num_list[k]=lefthalf[i] + i=i+1 + else: + num_list[k]=righthalf[j] + j=j+1 + k=k+1 + + while i < len(lefthalf): + num_list[k]=lefthalf[i] + i=i+1 + k=k+1 + + while j < len(righthalf): + num_list[k]=righthalf[j] + j=j+1 + k=k+1 + return num_list diff --git a/introduction_to_python/recursive_functions/3_merge_sort/solutions/solution.py b/introduction_to_python/recursive_functions/3_merge_sort/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/3_merge_sort/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/3_merge_sort/solutions/test_solution.py b/introduction_to_python/recursive_functions/3_merge_sort/solutions/test_solution.py new file mode 100644 index 0000000..d92e0ff --- /dev/null +++ b/introduction_to_python/recursive_functions/3_merge_sort/solutions/test_solution.py @@ -0,0 +1,4 @@ +def test_solution(): + import solution + assert solution.custom_sort([1,7,4,2]) == [1,2,4,7] + assert solution.custom_sort([2,1]) == [1,2] diff --git a/introduction_to_python/recursive_functions/3_towers_of_hanoi/README.md b/introduction_to_python/recursive_functions/3_towers_of_hanoi/README.md new file mode 100644 index 0000000..6ee24ac --- /dev/null +++ b/introduction_to_python/recursive_functions/3_towers_of_hanoi/README.md @@ -0,0 +1,27 @@ +# Towers Of Hanoi + +## Motivation +Towers of Hanoi is a mathematical puzzle where we have three rods and n disks. The objective of the puzzle is to move the entire stack from one rod to another, obeying the following simple rules: +1) Only one disk can be moved at a time. +2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved if it is the uppermost disk on a stack. +3) No disk may be placed on top of a smaller disk. + +For a further explanation on this concept, please consult the [wikipedia](https://en.wikiepdia.org/wiki/Tower_of_Hanoi) page. + +## Problem Description +Define a recursive Python function named `tower_of_hanoi`. The function consumes 4 arguments: +* `n` - the number of disks +* `from_rod` - the starting rod with all the disks +* `to_rod` - the desintation rod to end with all the disks +* `aux_rod` - an auxiliary rod to assist with moving the disks + +The function returns the minimal number of moves required to get all the disks from `from_rod` to `to_rod`. + +## Examples +``` +tower_of_hanoi(2) == 3 +tower_of_hanoi(3) == 7 +``` + +## Submission +* Submit your answers in the *solution.py* file within the *solutions* subdirectory within this directory diff --git a/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/.model_solution/solution.py b/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/.model_solution/solution.py new file mode 100644 index 0000000..21aa765 --- /dev/null +++ b/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/.model_solution/solution.py @@ -0,0 +1,2 @@ +def tower_of_hanoi(n , from_rod, to_rod, aux_rod): + return 1 if n == 1 else 1 + tower_of_hanoi(n-1, from_rod, aux_rod, to_rod) + tower_of_hanoi(n-1, aux_rod, to_rod, from_rod) diff --git a/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/solution.py b/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/solution.py new file mode 100644 index 0000000..aeb50ba --- /dev/null +++ b/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/solution.py @@ -0,0 +1 @@ +# Write your solution here diff --git a/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/test_solution.py b/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/test_solution.py new file mode 100644 index 0000000..23d8dcd --- /dev/null +++ b/introduction_to_python/recursive_functions/3_towers_of_hanoi/solutions/test_solution.py @@ -0,0 +1,3 @@ +def test_solution(): + import solution + assert solution.tower_of_hanoi(4) == 15 diff --git a/introduction_to_python/recursive_functions/README.md b/introduction_to_python/recursive_functions/README.md new file mode 100644 index 0000000..05cdb03 --- /dev/null +++ b/introduction_to_python/recursive_functions/README.md @@ -0,0 +1,14 @@ +# Exercises for Recursive Functions + + +| Exercise ID | Exercise | +|:-----------:|:--------:| +| easy_e1 | [Array Sum](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions) | +| easy_e2 | [Find Power](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions/1_find_power) | +| easy_e3 | [Count Down](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions/1_count_down) | +| easy_e4 | [Reverse String](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions/1_reverse_string) | +| medium_e1 | [Count Ways](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions/2_count_ways) | +| medium_e2 | [Fibonacci](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions/2_fibonacci) | +| medium_e3 | [Find Factorial](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions/2_find_factorial) | +| hard_e1 | [Merge Sort](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions/3_merge_sort) | +| hard_e2 | [Tower Of Hanoi](https://github.com/ByteAcademyCo/Introduction-To-Python/tree/master/exercises/recursive_functions/3_towers_of_hanoi) | diff --git a/software_theory/README.md b/software_theory/README.md index 3ee5a48..4828c05 100644 --- a/software_theory/README.md +++ b/software_theory/README.md @@ -1,8 +1,9 @@ # Exercise Organization -## Exercise Sections -* Databases -* SQL -* Networks -* Testing -* Python Libraries +| Section ID | Section Name | +|:-----------:|:--------:| +| 1 | [Databases](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/graph_traversal) | +| 2 | [SQL](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/sorting) | +| 3 | [Networks](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/bit_manipultion) | +| 4 | [Testing](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/string_manipulation) | +| 5 | [Python Libraries](https://github.com/ByteAcademyCo/Exercises/tree/master/algorithms/dynamic_programming) |