Answer:
Below is the complete code for this question:
import os #importing package
def parent_directory():#defining method parent_directory
dir = os.getcwd()#storing current working directory in dir
relative_parent = os.path.join(dir) #from dir, define relative_parent variable using join method
return os.path.dirname(relative_parent)#return the directory name using return keyword
print(parent_directory())#use print to invoke parent_directory method
Output:
/
Note:
This program executes in an online compiler, hence it returns "/"
Explanation:
The provided Python code imports the "os" package, after which it defines a method called "parent_directory" that uses the variable dir to store the current working directory through the "getcwd" method.
- Next, the variable "relative_parent" is defined, using the join method to store the directory value and returning its value.
- Lastly, the print function is called to output the method's result.