Question: Problem # 4 : Shopping Spree Isabel is going shopping using her debit card and has a tendency to overspend. Complete the function, balance _

Problem #4: Shopping Spree
Isabel is going shopping using her debit card and has a tendency to overspend. Complete the function, balance_remaining, which takes two arguments: initial, the integer amount of money Isabel starts with in her account; and transactions, the list of purchases Isabel is charging to her card.
Each transaction in the transactions list is a string of the following format:
'Store Name - $price'
The price is always an integer.
If Isabel can afford all of her transactions, your function should return the string
'Balance Remaining: $balance'
where balance is her remaining balance. If Isabel attempts to overspend, cancel the transaction (i.e., dont subtract the transaction amount from her current balance), and return the string
'Declined at Store Name: $balance'
where Store Name is the name of the store where her charge was declined, and balance is the amount of money she has remaining.
Function Call
Expected Return Value (string)
balance_remaining(1000,
['Best Buy - $500', 'Five Guys - $25'])
Balance Remaining: $475
balance_remaining(1050,
['Forever 21- $400', 'Hollister - $560',
'The Disney Store - $35', 'Starbucks - $4'])
Balance Remaining: $51
balance_remaining(1000,
['Hallmark - $550', 'Stop and Shop - $440',
'Taco Bell - $25'])
Declined at Taco Bell: $10
balance_remaining(1045,
['Hot Topic - $1002', 'Hollister - $500',
'Five Guys - $25'])
Declined at Hollister: $43

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!