Question: Step 3 . Create new module named person.py Follow these step - by - step instructions to create a Python class named Person within the
Step Create new module named person.py
Follow these stepbystep instructions to create a Python class named Person within the person.py module. The
person class has private variables for first name, last name, and the amount of money. Youll also write a
function to update the money amount with safeguards to prevent the balance from going negative. Additionally,
youll write a simple function to display the persons information.
Step : Define the Person Class and the Constructor
Create a class named Person.
Inside the class, define a method called init This is the constructor method that gets called
whenever you create a new Person object.
The init method should take three parameters:
firstname: the first name of the person.
lastname: the last name of the person.
amountofmoney: the amount of money the person has should be a floatingpoint number
I
inside the constructor:
Store the firstname and lastname as private variables use double underscores like firstname and
lastname
Store the amountofmoney as a private variable amountofmoney and ensure it is converted to a
f
loat using floatamountofmoney
Step : Write Getters and Setters for First Name and Last Name
Getters are functions that allow you to access private variables from outside the class.
Setters are functions that allow you to modify the value of private variables, but only if the new value is
valid.
For firstname:
Write a getfirstname method that returns the value of firstname.
Write a setfirstnamefirstname method to change the first name. Ensure that the new first name is
not empty by adding a check raise a ValueError if its empty
For lastname:
Write a getlastname method that returns the value of lastname.
Write a setlastnamelastname method to change the last name, with a similar check to ensure its
not empty.
Step : Write a Getter for the Amount of Money
Write a getamountofmoney method to return the value of amountofmoney. This will allow you
to check the persons balance later on
Step : Write the updatemoneyvalue Method
Create a method called updatemoneyvalueamount that takes a number positive or negative
This method will add the value of amount to amountofmoney.
However, if the resulting balance would go below the method should print a warning and not allow the
update. Use the if statement to check whether adding amount would result in a negative balance.
Step : Write the displayInfo Method
Create a displayInfo method that prints out the persons full name and current balance in a readable format.
name: Albert Einstein money: $
This is the output for a person whose first name is Albert, last name is Einstein and has $
Step : Write the main Function
Write a main function that creates a Person object, displays the persons info, performs a few
transactions, and displays the updated info after each transaction.
Test the updatemoneyvalue method by attempting to withdraw more money than the person has and
ensure it shows a warning.
def main None:
testperson PersonAlbert "Einstein",
testperson.displayInfo
testperson.updatemoneyvalue
testperson.displayInfo
testperson.updatemoneyvalue
testperson.displayInfo
testperson.updatemoneyvalue
testperson.displayInfo
Step : Ensure the Program Runs
Add the standard Python entry point to run your code:
Output for running code:
name: Albert Einstein money: $
name: Albert Einstein money: $
name: Albert Einstein money: $
Transaction cannot be done due to lack of funds.
name: Albert Einstein money: $
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
