What is the expected result of the following code?
import os os.mkdir('pictures') os.chdir('pictures') os.mkdir('thumbnails') os.chdir('thumbnails') os.mkdir('tmp') os.chdir('../') print(os.getcwd())
- It prints the path to the pictures directory
- It prints the path to the root directory
- It prints the path to the thumbnails directory
- It prints the path to the tmp directory
Explanation: Let’s analyze this code snippet:
- The first line imports the os module, which handles functions that interact with the Operating System.
- The second line creates a directory named pictures.
- The third line changes the current working directory to the pictures folder.
- The fourth line creates a directory named thumbnails.
- The fifth line changes the current working directory to the thumbnails folder.
- The sixth line creates a directory named tmp.
- The seventh line exits the current working directory.
- The eighth line prints the path to the current working directory which is now the pictures folder.
More Questions: Python Essentials 2 – Module 4 Test
Please login or Register to submit your answer