INSTRUCTIONS: Read the problem below and provide the correct code. Sample input and output are also given along with the template code to be used. The programming language is Python.
Operations
In mathematics and computer science, an operation is an event that is carried out to satisfy a given task. Basic operations of a computer system are input, processing, output, storage, and control.
Basic Operators
An operator is a symbol that indicates an operation to be performed. We are familiar with operators in mathematics; operators used in computer programming are—in many ways—similar to mathematical operators.
Division Operator
We all learnt about division—and the division operator—in school. You probably know of both these symbols as representing division:
Modulus Operator
Modulus can be represented either as (mod or modulo) in computing operation. Modulus comes under arithmetic operations. Any number or variable which produces absolute value is modulus functionality. Magnitude of any function is totally changed by modulo operator as it changes even negative value to positive.
Operators
In the realm of programming, operators refer to the symbols that perform some function. They are tasked with instructing the compiler on the type of action that needs to be performed on the values passed as operands. Operators can be used in mathematical formulas and equations. In programming languages like Python, C, and Java, a variety of operators are defined.
INSTRUCTIONS: Read the problem below and provide the correct code. Sample input and output are also given along with the template code to be used. The
![that file. Once you are done adding elements to the filesystem, you should print the directory structure in the
specified format.
12
Users-C
Windows-C
Required modifications: 1. Insertion of a new element 2. Printing of the directory from the root node. 3.
ProgramFiles-c
Adobe-C, ProgramFiles
Steam-C, ProgramFiles
ferdie-C,Users
Parsing of the input.
Input Format
john-C,Users
guest-C, Users
Firmware-C, windows
First line is the name of the root directory.
System-C,Windows
Documents-C, Users, ferdie
Downloads-C, Users, ferdie
Second line, n, is the number of subdirectories that follows.
For each line that follows, it shows the following format:
Filename-root node, next path,next path.,.
Sample Output 0
Constraints
1. You may assume that the filenames are all alphabetical characters with no special characters.
Users
ferdie
2. n< 100
Documents
Downloads
3. The maximum path length is 20 (including the root directory).
john
guest
Windows
4. You may assume that there are no similar filenames within the same directory but may exist outside of the
directory (much like a normal filesystem).
Firmware
System
ProgramFiles
Adobe
Output Format
Steam
You should follow the output format indicated in the sample test case with the ordering of files based
chronologically.
For the spacing, use the tab (1) character for the subdirectories.
Rootdir
Subdirl
subsubdirl
subsubdir2
Subdir2
Subdir3
subsubdirl](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fef867b47-269c-4411-97a9-7125d900ede7%2F58dd3e07-9f3d-434f-9e4a-fdba5fc5fcbb%2Fmggpuc6_processed.png&w=3840&q=75)
![def insert(self, filename, path):
"""Inserts a new file with the given path starting from the root node.
class FileNode:
def init_(self, filename, depth=0):
"This function initializes our FileNode
Args:
Args:
filename (string): The filename of the current node.
depth (int, optional): The depth of the current node,. Defaults to 0.
filename (string): The filename of the folder to be inserted.
path (string): The path of the folder to be inserted
self.root.insert(filename, path, 1)
self.filename = filename
self.depth = depth
* Hint: It is best to implement the subdirectory into a dictionary with keys being the filename and the values
being the actual object FileNode.
self.subdirectories = ()
def print_system(self):
"Prints the directory in the given format"
self.root.print_dir()
def delete(self):
"This function overrides the default deletion of the current object and also deletes the subdirectories"""
for v in self.subdirectories.values ():
if
-name == "__main__":
root_dir = input()
n = int(input())
filenames = []
del v
self.subdirectories.clear ()
def insert(self, filename, path, depth):
"This function inserts the file into a specific path.
If the path does not exist, then the folder is not created.
for i in range(n):
# Part C. Implement parsing of input lines.
pass
Args:
filename (string): The filename of the current folder to be inserted
path (lists of string): The path of the filename
depth (int): The depth of the node to be inserted.
##
I DO NOT MODIFY BELOM ###
fs = FileSystem(root_dir)
for f, p in filenames:
fs.insert(f, p)
* Part A. Implement the insertion of a new file here. If the given path does not exist, then you may skip the
file.
fs.print_system()
def print_dir(self):
"This prints the current directory and accesses the subdirectories as well.""
* Part B. Implement the printing of the directory here.
* You should access subdirectories first before moving to the next folder within the same directory.
: Do not modify this object ##
class Filesystem:
definit (self, root_dir):
"This is the FileSystem implementation. A root node is required once an instance is created
Args:
root_dir (string): Filename of the root node for the file system.
self.root = FileNode (root_dir)
def delete_(self):
"Deletes the filesystem by deleting the root and deleting the subdirectories automatically due to the override
function.""
del self.root](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fef867b47-269c-4411-97a9-7125d900ede7%2F58dd3e07-9f3d-434f-9e4a-fdba5fc5fcbb%2F90i9xgb_processed.png&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)