Python Assignment - 3
Python Assignment - 3
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 :
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.
PROGRAM :
OUTPUT :