diff --git a/projects/006-run-length-decoding/python/main.py b/projects/006-run-length-decoding/python/main.py index e69de29..bac8ebc 100644 --- a/projects/006-run-length-decoding/python/main.py +++ b/projects/006-run-length-decoding/python/main.py @@ -0,0 +1,35 @@ +''' +Run-length encoding is a simple data compression technique that can be effective +when repeated values occur at adjacent positions within a list. + +Compression is achieved by replacing groups of repeated values with one copy of the value, +followed by the number of times that it should be repeated. +For example, the list +`["A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B","B","A","A","A","A","A","A","B"]` +would be compressed as `["A",12,"B",4,"A",6,"B",1]`. + +Decompression is performed by replicating each value in the list the number of times indicated. + +Write a recursive function that decompresses a run-length encoded list. +Your recursive function will take a run-length compressed list as its only argument. +It will return the decompressed list as its only result. + +Create a main program that displays a run-length encoded list and the result of decoding it. +''' + +def decompression(array): + if len(array) == 0: + return [] + + value = array[0] + count = array[1] + finalvalue = [value] * count + decompression(array[2:]) + + return finalvalue + +def main(): + array = ["A", 12, "B", 4, "A", 6, "B", 1] + print(decompression(array)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/projects/final-project/main.py b/projects/final-project/main.py new file mode 100644 index 0000000..6a178fa --- /dev/null +++ b/projects/final-project/main.py @@ -0,0 +1,116 @@ +''' +# **Cataloger of Household elements 🏡** + +This project is to develop a household element cataloger, +a tool that helps users catalog and manage elements in their homes. +The cataloger will use recursion to explore home environments in depth, gathering information about elements, +such as name, location, and category. +It will also provide functionality to search, add, edit, and delete elements from the catalog, +simplifying home inventory management. + + +## **elementive 🎯** +The goal of the project is to provide users with a practical tool for cataloging and keeping +track of elements in their home. +Using variables, strings, mathematical calculations, conditional operators, loops, functions, arrays, JSON elements, +and recursive functions, the cataloger will enable users to effectively organize their household elements +and obtain detailed information about them. + +## **Recursive exploration of home environments 🔁** + +- Using a recursive function, explore home environments, such as rooms and closets, to identify the elements present. +- Gather information about elements, such as name, location, and category. +- Use an appropriate data structure, such as an array of JSON elements, to store element information. + +## **Adding new elements ➕** + +- Using a function, allow the user to add new elements to the catalog. +- Capture the element's information, such as name, location, and category, and create a new JSON element with that information. +- Add the element to the home element catalog. + +## **Modify existing elements ✍️** + +- Using a recursive function, allow the user to search and edit existing elements in the catalog. +- Allow the user to edit the element's information, such as name, location, or category. +- Update the corresponding JSON element in the catalog with the new information. + + +## **element deletion ➖** + +- Using a recursive function, allow the user to search for and delete existing elements in the catalog. +- Remove the corresponding JSON element from the home element catalog. + +## **Limitations ✋** + +- The project focuses on cataloging and management of household elements, without including features such as element + quantity management or integration with more complex inventory systems. +- Interactions with external databases or other sources of additional information are not considered. + +## **Project Duration ⏲️** + +Considering the functionality required and the use of the specified constructs, +the project is expected to take about 1 to 2 days to complete. +''' + +def check_environment(catalog, index = 0, room = ""): + if catalog: + if index == 0: + room = input("Please input which room do you want to explore: ") + if catalog[index]["location"] == room: + print(catalog[index]) + return catalog + index += 1 + return check_environment(catalog, index, room) + return catalog + +def add_element(catalog): + name = input("Please input the name of the element: ") + location = input("Please input the position of the element: ") + category = input("Please input the category of the element: ") + element = {"name": name,"location": location,"category": category} + catalog.append(element) + print("element added correctly!") + +def change_element(catalog, name): + if catalog: + if catalog[0]["name"] == name: + catalog[0]["name"] = input("Please input new name: ") + catalog[0]["location"] = input("Please input new location: ") + catalog[0]["category"] = input("Please input new category: ") + print("Element modified correctly") + return catalog + return change_element(catalog[1:], name) + print("Element not found\n", catalog) + return catalog + +def delete_element(catalog, name, index = 0): + if catalog: + if catalog[index]["name"] == name: + del catalog[index] + print("Element deleted correctly") + return catalog + index += 1 + return delete_element(catalog, name, index) + print("element not found\n", catalog) + return catalog + +def main(): + catalog = [{"name": "Fra", "location": "Living", "category": "Computer"}, + {"name": "Mattia", "location": "Kitchen", "category": "Box"}, + {"name": "Simone", "location": "Bathroom", "category": "Soap"}] + userchoice = input("Please choose one of the following options\n 1. Search\n 2. Add\n 3. Edit\n 4. Delete\n") + while userchoice != "": + if userchoice == "1": + check_environment(catalog) + elif userchoice == "2": + add_element(catalog) + elif userchoice == "3": + name = input("Please input the name of which element you would like to modify?\n") + change_element(catalog, name) + elif userchoice == "4": + name = input("Please input the name of which element you would like to delete?\n") + delete_element(catalog, name, index = 0) + userchoice = input("Please choose one of the following options\n 1. Search\n 2. Add\n 3. Edit\n 4. Delete\n") + +if __name__ == '__main__': + main() \ No newline at end of file