0% found this document useful (0 votes)
6 views2 pages

program 7

Uploaded by

PRASANN PRATIK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

program 7

Uploaded by

PRASANN PRATIK
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

7.

Develop a program to backing Up a given Folder (Folder in a current working directory)


into a ZIP File by using relevant modules and suitable methods.
import shutil

def backup_folder_to_zip(folder_path):
# Create a zip file from the folder
shutil.make_archive(folder_path, 'zip', folder_path)
print(f"Folder '{folder_path}' has been backed up successfully!")

# Example usage
folder_to_backup = "C:\\Users\\Ajay C P\\Untitled Folder\\organizingfiles\\lists" # Specify
the folder you want to back up
backup_folder_to_zip(folder_to_backup)

8. '''Write a function named DivExp which takes TWO parameters a, b and returns a value c
(c=a/b). Write suitable assertion for a>0 in function DivExp and raise an exception for
when b=0. Develop a suitable program which reads two values from the console and calls
a function DivExp'''
def DivExp(a, b):
# Check if a is greater than 0
assert a > 0, "a must be greater than 0"

# Check if b is 0 and raise an exception if true


if b == 0:
raise ValueError("b cannot be 0 as division by zero is not allowed")

# Perform the division and return the result


c=a/b
return c

# Main program to read values and call the function


def main():
try:
# Read input values from the user
a = float(input("Enter the value of a (should be greater than 0): "))
b = float(input("Enter the value of b (should not be 0): "))

# Call the DivExp function and print the result


result = DivExp(a, b)
print(f"The result of {a} / {b} is: {result}")

except ValueError as ve:


# Handle cases where b is 0 or invalid input
print(f"Error: {ve}")

except AssertionError as ae:


# Handle case where a <= 0
print(f"Error: {ae}")

except Exception as e:
# Handle any unexpected exceptions
print(f"Unexpected error: {e}")

# Run the main program


if __name__ == "__main__":
main()

You might also like