Professional Documents
Culture Documents
Question Bank2 PWP
Question Bank2 PWP
9) Design a python program to create class to calculate area of triangle and circle and print the
result?
10) Write a Python Program to calculate factorial of given number.
12) Write a python program for importing module for addition and subtraction of 2 numbers.
13) Write a python program to define a module for swapping the two values?
14) Write a python program to create class STUDENT with Roll Number and Name and display
its contents.
15) Explain class inheritance in Python with an example?
- Inheritance lets us create new classes that automatically have the attributes and
behaviors of existing classes.
- It's like passing down traits from parents to children. For example, a "Dog" class
can inherit traits like "Animal" from a superclass.
- With inheritance, we can reuse code and avoid repeating the same code in
multiple classes.
- Subclasses can add their own unique features or change existing ones without
affecting the superclass.
- Inheritance helps in organizing code logically and makes it easier to understand
and manage large projects.
16) Write a python program of Inheritance?
OR
17) Differentiate between Inheritance and composition class?
Method Overloading:
Method overloading means having multiple methods with the same name but
different types or numbers of inputs.
In Python, we use default values or variable arguments to achieve method
overloading.
It helps us write cleaner code by having one method name for similar operations.
Method Overriding:
Method overriding means changing the behavior of a method in a subclass that was
defined in the superclass.
It allows us to customize how a method works in different classes.
In method overriding, the method name and parameters remain the same.
Example:
19) Write a python program for importing module for addition and subtraction of 2 numbers.
20) Explain file handling and Exception Handling with Example.
File handling and exception handling are crucial aspects of programming in Python. Here's a
concise explanation along with an example for a 4-mark response:
**Example**: