0% found this document useful (0 votes)
3 views5 pages

Python Assignment - 3

The document outlines a Python assignment that includes developing a program for backing up a folder into a ZipFile, explaining assertions and raising exceptions, detailing logging types, and illustrating operator overloading and polymorphism. It also includes a task to create a Student class that calculates total marks and percentage. Additionally, it mentions the __init__ and __str__ methods with examples.

Uploaded by

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

Python Assignment - 3

The document outlines a Python assignment that includes developing a program for backing up a folder into a ZipFile, explaining assertions and raising exceptions, detailing logging types, and illustrating operator overloading and polymorphism. It also includes a task to create a Student class that calculates total marks and percentage. Additionally, it mentions the __init__ and __str__ methods with examples.

Uploaded by

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

PYTHON ASSIGNMENT - 3

2. Develop a program to backing up a given folder into a ZipFile.

PROGRAM :

OUTPUT :
3. Briefly explain Assertion and Raising Exception with example.
Assertions :
➢ An assertion is a sanity check to make sure your code isn’t doing something obviously wrong.
➢ Assert statement consists of the following:
• The assert keyword. Eg.
• A condition.
• A comma.
• A string to display when the condition is False.

Raising Exceptions :
➢ Python raises an exception whenever it tries to execute invalid code.
➢ Exceptions are raised with a raise statement.
➢ In code, a raise statement consists of the following:
• The raise keyword
• A call to the Exception() function.
• A string with a helpful error message passed to the Exception() function.

Eg.

PROGRAM :
OUTPUT :
6. Explain Logging Types.
Logging is a great way to understand what’s happening in your program and in what order its happening.
Logging Levels :
➢ Messages can be logged at each level using a different logging function.
7. Illustrate Operator Overloading and Polymorphism in Python with an Example.
OPERATOR OVERLOADING :
Python operator overloading refers to a single operator's capacity to perform several operations based on the class
(type) of operands.

Eg.

POLYMORPHISM :

The word "polymorphism" means "many forms", and in programming it refers to


methods/functions/operators with the same name that can be executed on many objects or
classes.

Eg.
9. Develop a program that uses class Student which prompts the user to enter marks
in three subjects and calculates total marks, percentage and displays the score card
details.

Student Class Demo

PROGRAM :

OUTPUT :

10. Explain __init__ & __str__ with an example.

You might also like