Write a Python program that uses the os module to list all files and directories in the current working directory. Return the list.
Example:
This will depend on the files and directories present in your current working directory.
The os module in Python provides functions for interacting with the operating system. os.getcwd() is a method in python to get the current working directory. os.listdir() is used to get the list of all files and directories in the specified directory.
import os
def list_files_directories():
# Get current working directory
cwd = os.getcwd()
# List all files and directories
return os.listdir(cwd)
print(list_files_directories())
NOTEOwing to browser caching, any code input into the Trinket IDE might carry over across page refreshes or when transitioning between different questions. To commence with a clean slate, either click on the 'Reset Button' found within the IDE's Hamburger icon (☰) menu or resort to using Chrome's Incognito Mode.