Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use Python: Path Adjuster Finish the codes below: def changePath (initial, changes): # ADD YOUR CODE HERE return None # CHANGE OR REMOVE THIS LINE
Use Python:
Path Adjuster
Finish the codes below:
def changePath (initial, changes): # ADD YOUR CODE HERE return None # CHANGE OR REMOVE THIS LINE if __name__ == "__main__": start = input("Enter the starting path: ") update = input("Enter the path modification: ") print("Final path:", changePath(start, update))
A Unix file path consists of a series of directory names, starting with a slash and separated by forward slash characters. For example, /usr/local/bin/ has three directories (the final directory may or may not be followed by a slash) Complete the changePath() function in the "paths.py" file, which takes two string arguments, representing a current path and a new "updated" path (a string of directory names) with which to update the current path, according to the following rules 1. If the updated path begins with a forward slash, it is an absolute path, and should completely replace the current path 2. Avalid directory name (letters or digits, followed by a slash) should just be appended to the current path, with a single forward slash separating the two. For example, "Nar/ib" plus "postfix/" would produce "/var/lib/postfix/ 3. A directory "name" of exactly (two consecutive periods and a slash) means "go up one level to the preceding directory", so the last/latest directory name should be removed from the current path. The sole exception to this is if the current path is only a single slash (the root directory, in which case you should ignore the and proceed to the next directory in the updated path. Be careful of removing the final (topmost) directory! "/usr/local/bin/" plus "../share/man/" would produce "/usr/local/share/man/ (the eliminates "bin/). Likewise, "Nar/tmp/ plus would simply produce "M" (the first two instances of remove "tmp/" and "var, but you can't go back before the starting slash) You may find the string method rfind helpful here; it returns the index of the final (rightmost) occurrence of a particular substring. 4. For simplicity, your code should make sure that the current path always begins with a single forward slash; if it doesn't have one, be sure to add it! 5. Forward slashes will always appear one at a time (i.e., you should never see "Ir in a path) change Path returns a string representing the new file path
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started