473,385 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

JES account balance function

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
2 1886
bvdet
2,851 Expert Mod 2GB
You must have some code framework in place to work with. What is "numbers.number"?
Mar 26 '13 #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

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

Similar topics

3
by: NoEd | last post by:
I was talking to a couple guys at one of the hospitals I consult with, and they indicated their 401K is charging them $8 per quarter and .0875% based on the value in their accounts at the end of...
59
by: Michael C | last post by:
eg void DoIt() { int i = FromString("1"); double d = FromString("1.1"); } int FromString(string SomeValue) {
2
by: carl.barrett | last post by:
I have a text file that needs to be imported into a table on a daily basis. The data is replaced each day except for one field. This field has an account balance in it and needs to be added to...
1
by: ryann18 | last post by:
Can someone please help with this modifying Account problem!?!?! Modify the Account class so that it also permits an account to be opened with just a name and an account number, assuming an...
4
by: automode | last post by:
can someone kindly help me with this program.PLEASe Create a base class Bank of a bank account with member functions to allow withdrawal, deposit and calculation of balance. Account...
2
by: cheongsiwei | last post by:
Need some helps here >.< The project i required to complete : Create a base class Bank of a bank account with member functions to allow withdrawal, deposit and calculation of balance. ...
3
by: Paul H | last post by:
I have a transactions table and a balance table that look something like this: tblTransactions TransactionID (PK Autonumber) ClientID TransactionDate TransactionAmount (currency field, values...
5
by: Albert-jan Roskam | last post by:
Hi, I wrote the program below to merge all xls files in a given directory into one multisheet xls file. It uses xlwt and xlrd. The xls files I use for input are generated by Spss. When I open and...
5
by: kirayamato1992 | last post by:
i wrote some codes for my assignments. then it came out several problems involving illegal local function definition. #include <iostream> using namespace std; void system_module(); void...
1
by: blknmld69 | last post by:
How do i get my program to add a $15 fee if the balance falls below $400? import java.util.Scanner; // Needed for the Scanner class public class BankCharges { public...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.