0% found this document useful (0 votes)
5 views

Python Conceptual Test

The document outlines the requirements for creating several Python programs, including a Bank Account system with custom exception handling, an ATM machine simulation, a class hierarchy for a Smartphone, an abstraction example, and a Book class with encapsulated details. Each program has specific functionalities such as managing deposits and withdrawals, dispensing money, and modeling electronic items with inheritance. The document emphasizes proper error handling and encapsulation in object-oriented programming.

Uploaded by

hnbhat.jsp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Python Conceptual Test

The document outlines the requirements for creating several Python programs, including a Bank Account system with custom exception handling, an ATM machine simulation, a class hierarchy for a Smartphone, an abstraction example, and a Book class with encapsulated details. Each program has specific functionalities such as managing deposits and withdrawals, dispensing money, and modeling electronic items with inheritance. The document emphasizes proper error handling and encapsulation in object-oriented programming.

Uploaded by

hnbhat.jsp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Each Ques on Carries 2 Marks

1. You are required to build a program that simulates the func onality of a Bank Account system using custom
excep on handling.

The program should start with a class called BankAccount. This class should manage a bank account’s balance, which
starts at 0. The class should have two key methods: deposit and withdraw.

 The deposit method allows a user to add money to their account. However, if the amount the user tries to
deposit is less than or equal to 0, the program should raise a custom excep on called
Nega veAmountExcep on to indicate that deposits must be posi ve.

 The withdraw method allows a user to take money out of their account. But, before comple ng the
transac on, the program should check if the withdrawal amount is valid. If the user tries to withdraw more
than the available balance, the program should raise a custom excep on called InsufficientFundsExcep on.
If the user a empts to withdraw an amount that is less than or equal to 0, the program should raise
Nega veAmountExcep on.

Next, create the custom excep ons Nega veAmountExcep on and InsufficientFundsExcep on, which should be
raised when the deposit or withdrawal condi ons aren’t met.

In the main part of the program, create an object of the BankAccount class. The program should accept inputs from
the user for deposits and withdrawals and process them accordingly. If an excep on is raised during a transac on
(like trying to deposit a nega ve amount or withdrawing more than the available balance), handle the excep on
gracefully by prin ng an appropriate error message, but don’t stop the execu on of the program.

2. Simulate the func onality of an ATM machine in Python. The ATM should allow users to withdraw money, and
when a withdrawal is made, the system needs to create an object represen ng the money dispensed.

The ATM has a behaviour called dispense that takes in an amount to be withdrawn. When a user invokes this method
with a specific amount, the ATM should create an object of the Money class. The Money class holds a state called
value, which represents the amount of money withdrawn.

The dispense method should ini alize the value of the Money object with the amount provided by the user when
the method is called. A er crea ng the Money object, the method should return this object.

In the main part of the program, a er crea ng an ATM object, you need to invoke the dispense method by passing an
amount. The method will return a Money object, and you should display the value stored in this object to confirm
that the ATM has dispensed the correct amount.

3. You need to create a program that models a Smartphone as part of a class hierarchy using mul level inheritance.

Start by crea ng a base class called ElectronicItem. This class should have a constructor that takes one argument,
brand, and assigns it to an instance variable.

Next, create another class called Device that inherits from ElectronicItem. The Device class should have its own
constructor, which takes two arguments: brand and model. It should ini alize both the brand and model within its
constructor.

Finally, create a third class called Smartphone that inherits from Device. This class should have a constructor that
takes three arguments: brand, model, and price. It should ini alize the brand, model, and price within its constructor.

Once the classes are set up, write a main program that creates a Smartphone object by passing in a brand, model,
and price. A er that, print out the brand, model, and price.
4. Write a program to achieve abstrac on (excluding the examples given in class)

5. Create a Book class that encapsulates the details of a book. The Book class should have three states: tle, author,
and edi on. Implement these states in a way that they cannot be directly accessed or modified from outside the
class, ensuring proper encapsula on.

You might also like