python: In this assignment, you will use a dictionary called balances to track money balances for people (think of it as a very insecure banking interface). This dictionary will be a global variable in your script.   You will create two functions, depositMoney() and withdrawMoney(), that will be used to manipulate this dictionary to add or subtract money from a person's account. These functions will return a tuple of information. The functions you need to create are described in the function specifications below.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

python:

In this assignment, you will use a dictionary called balances to track money balances for people (think of it as a very insecure banking interface). This dictionary will be a global variable in your script.

 

You will create two functions, depositMoney() and withdrawMoney(), that will be used to manipulate this dictionary to add or subtract money from a person's account. These functions will return a tuple of information. The functions you need to create are described in the function specifications below.

 

Function 1: depositMoney(name, amount)

"""

Given a person's name and amount of money, adds amount to their account.

If person does not have an account, one is created for them.

 

Parameters:

name - string

amount - float, amount >= 0

Returns: 

bool - True if account existed, False if account had to be created

float - new balance for person

"""

 

Function 2: withdrawMoney(name, amount)

"""

Given a person's name and amount of money, withdraws amount from their account.

If person does not have enough balance, function indicates overdraft

If person does not have an account, function indicates error

 

Parameters:

name - string

amount - float, amount >= 0

Returns: 

bool - True if account existed, False if not

bool - False if existing account had enough balance for withdrawal, True if account went in to overdraft or didn't exist

float - New balance for person (or 0 if account did not exist)

"""

 

Before beginning your implementation, consider algorithm design. Understand the problem as outlined in the function specification, and look at the methods available when you use dictionaries. Specifically, you will want to become familiar with:

  • dict.keys()
  • dict.get()
  • dict.update()
  • dict[keyValue]

Define the global dictionary balances and these functions in a file.

You will create two functions, depositMoney) and withdrawMoney(), that will be used to manipulate this dictionary to add or subtract money from a person's account.
These functions will return a tuple of information. The functions you need to create are described in the function specifications below.
Function 1: depositMoney (name, amount)
Given a person's name and amount of money, adds amount to their account.
If person does not have an account, one is created for them.
Parameters:
name - string
amount - float, amount >= 0
Returns:
bool - True if account existed, False if account had to be created
float - new balance for person
Function 2: withdrawMoney (name, amount)
Given a person's name and amount of money, wvithdraws amount from their account.
If person does not have enough balance, function indicates overdraft
If person does not have an account, function indicates error
Parameters:
name - string
amount - float, amount >= 0
Returns:
bool - True if account existed, False if not
bool - False if existing account had enough balance for withdrawal, True if account went in to overdraft or didn't exist
float - New balance for person (or 0 if account did not exist)
Transcribed Image Text:You will create two functions, depositMoney) and withdrawMoney(), that will be used to manipulate this dictionary to add or subtract money from a person's account. These functions will return a tuple of information. The functions you need to create are described in the function specifications below. Function 1: depositMoney (name, amount) Given a person's name and amount of money, adds amount to their account. If person does not have an account, one is created for them. Parameters: name - string amount - float, amount >= 0 Returns: bool - True if account existed, False if account had to be created float - new balance for person Function 2: withdrawMoney (name, amount) Given a person's name and amount of money, wvithdraws amount from their account. If person does not have enough balance, function indicates overdraft If person does not have an account, function indicates error Parameters: name - string amount - float, amount >= 0 Returns: bool - True if account existed, False if not bool - False if existing account had enough balance for withdrawal, True if account went in to overdraft or didn't exist float - New balance for person (or 0 if account did not exist)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Dictionary
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education