By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

JES account balance function

P: 2
am supposed to complete the following five functions, i have no idea how to do this. I will greatly appreciate any help

The following five functions allow you to maintain the running balance of an account and print out lines relating to each transaction.

You'll also need a global variable (balance?) to maintain the running balance of the account.

1. def setBalance(amt): # Defines (but doesn't print) the value of the account balance

2. def printBalance(): # Displays current balance as a money value with a heading

3. def printLedgerLine(date, amount, details): # with items (and the balance) spaced and formatted

4. def deposit (date, details, amount): # Alter the balance and print ledger line

5. def withdraw(date, details, amount): # Alter the balance and print ledger line

Your task is to:
complete the five (very short) functions by creating the code for the body of each function, and
demonstrate that you code works by calling the functions, as is demonstrated below.

So when these functions are called
e.g.

setBalance(500)
printBalance()
withdraw("17-12-2012", "BP - petrol", 72.50)
withdraw("19-12-2012", "Countdown", 55.50)
withdraw("20-12-2012", "munchies", 1.99)
withdraw("22-12-2012", "Vodafone", 20)
deposit ("23-12-2012", "Income", 225)
withdraw("24-12-2012", "Presents", 99.02)
printBalance()
The output is something like this:

Current Balance is $ 500.00
17-12-2012 BP - petrol $ 72.50 $ 427.50
19-12-2012 Countdown $ 55.50 $ 372.00
20-12-2012 munchies $ 1.99 $ 370.01
22-12-2012 Vodafone $ 20.00 $ 350.01
23-12-2012 Income $ 225.00 $ 575.01
24-12-2012 Presents $ 99.02 $ 475.99
Current Balance is $ 475.99

So far i got:
Expand|Select|Wrap|Line Numbers
  1. def setBalance(amount):
  2. global balance
  3. assert isinstance(amount,numbers.number)
  4. balance = euros
  5. printNow(balance)
Im not sure whats wrong, i only started programming a week ago, im so lost, please help me with this assignment
thnx
Mar 26 '13 #1
Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
You must have some code framework in place to work with. What is "numbers.number"?
Mar 26 '13 #2

P: 2
This is nearly the finished code except i need to the printledgerline function and i dont know what that is. please help me with this function

Expand|Select|Wrap|Line Numbers
  1. g_balance = 0
  2.  
  3.  
  4. def setBalance(amount):
  5.     global g_balance
  6.     if amount:
  7.         g_balance = amount
  8.  
  9.  
  10. def printBalance():
  11.     global g_balance
  12.     if g_balance >=0:
  13.       printNow("%s $%0.2f" % ("Currrent balance is",g_balance))
  14.  
  15.  
  16. def deposit (date, details, deposit):
  17.   global g_balance
  18.   g_balance = g_balance + deposit
  19.   printNow("%s %10s \t\t$%10.2f \t$%10.2f" % (date,details,deposit, g_balance))
  20.  
  21. def withdraw (date, details, withdraw):
  22.   global g_balance
  23.   g_balance = g_balance - withdraw
  24.   printNow("%s %15s \t\t$%10.2f \t\t$%10.2f" % (date,details,withdraw, g_balance))
Apr 1 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.