diff --git a/path-directories/path_directories.py b/path-directories/path_directories.py new file mode 100644 index 0000000..4882ce2 --- /dev/null +++ b/path-directories/path_directories.py @@ -0,0 +1,14 @@ +from pathlib import Path + +# Create a Path object +pathOne=Path("path-directories") # Path object for a directory +print(pathOne.exists()) # check if the directory exists + +for file in pathOne.glob("*.py"): + print(file) # print all the python files under the 'path-directories' directory + +# pathOne.rmdir() # remove the directory + +# Get the current directory +current_directory = Path.cwd() +print(current_directory) diff --git a/python-data-structure/handling_exception.py b/python-data-structure/handling_exception.py new file mode 100644 index 0000000..7a7396a --- /dev/null +++ b/python-data-structure/handling_exception.py @@ -0,0 +1,12 @@ + +try: # General exception + age=int(input("Age: ")) + income=50000 + risk=income/age + print(f"Risk: {risk:.3f}") # 3 decimal places + +except ZeroDivisionError: # Specific exception + print("Age cannot be zero") + +except ValueError: # Specific exception + print("Invalid value") \ No newline at end of file