Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For this task, you are to write code that handles the transfer of funds between two bank accounts. Instructions As this task relates to tranferring

image text in transcribed

For this task, you are to write code that handles the transfer of funds between two bank accounts. Instructions As this task relates to tranferring funds between bank accounts, a BankAccount class has been provided, which supports depositing and withdrawing funds. A simple interactive loop has already been implemented, which allows the user to repeatedly transfer funds from one account to another. a) Defining the transfer_funds function You are to write a function called transfer_funds with three parameters: the amount to transfer, the account the funds are coming from, and the account the funds are going to. It should use the appropriate instance methods on each of the accounts to update their balances as required. b) Preventing negative balances If you tested your solution thoroughly in the previous part, you probably came across a logic error in the program-there's nothing to stop us from transferring funds from an account, even if the account balance becomes negative! You are to fix this problem by raising an exception and preventing the account balance from becoming negative. You should do this by raising a valueError in the appropriate place in the BankAccount class. Hint: The order in which the withdrawal and deposit occur in transfer_funds matters--the wrong order will result in the creation of free money! c) Exception handling At this point, the program prevents a transfer occurring if there aren't enough funds in the "from" account. However, simply crashing a program isn't a very nice user experience. You are to modify your program so that it handles the ValueError and displays ***Transfer cancelled*** to the user. The program should otherwise continue as normal, with the user being asked whether they would like to perform another transaction. A failed transaction should not result in either account balance changing. Hint: A little rusty at exception handling? Refer back to Topic 8 and the associated lab for examples. Criteria During marking we will check that your program: - Defines a function with correct parameters and name for transfer_funds. (2 marks) - Calls the appropriate methods to deposit and withdraw funds. Does not directly access the balance instance variable from within transfer_funds. (2 marks) - Must not accept amount

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Marketing The Ultimate Marketing Tool

Authors: Edward L. Nash

1st Edition

0070460639, 978-0070460638

More Books

Students also viewed these Databases questions