Implement a cd() method that behaves like running cd <destination> in a terminal and then calling pwd. The base version takes two inputs:
current_dir: the current working directorydestination: the destination directoryGiven the current working directory current_dir and the destination directory destination, implement the cd() method to simulate the behavior of running cd <destination> followed by pwd in a terminal. The method should return the absolute path of the new current working directory.
current_dir = "/Users/ai/Interview", destination = "Git"
"/Users/ai/Interview/Git"current_dir = "/Users/ai/Interview", destination = "../Git"
"/Users/ai/Git"current_dir = "/Users/ai/Interview", destination = "/Git"
"/Git"current_dir and destination are non-empty strings.current_dir is an absolute path.destination can be a relative or absolute path.os.path module in Python to handle file paths..., ., and absolute paths.`python import os
def cd(current_dir, destination): # Join the current directory and destination new_dir = os.path.join(current_dir, destination)
# Normalize the path to remove any redundant separators or parent directory references
new_dir = os.path.normpath(new_dir)
# Return the absolute path of the new current working directory
return os.path.abspath(new_dir)
current_dir = "/Users/ai/Interview" destination = "Git" print(cd(current_dir, destination)) # Output: "/Users/ai/Interview/Git" `
This solution uses the os.path module to join the current directory and destination, normalize the path, and return the absolute path of the new current working directory. The os.path.normpath function is used to remove any redundant separators or parent directory references, ensuring the path is in its simplest form.