Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #41874 > unrolled thread

JES account balance function help urgent!

Started bykidoman3@gmail.com
First post2013-03-26 03:30 -0700
Last post2013-03-26 06:56 -0400
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  JES account balance function help urgent! kidoman3@gmail.com - 2013-03-26 03:30 -0700
    Re: JES account balance function help urgent! Dave Angel <davea@davea.name> - 2013-03-26 06:56 -0400

#41874 — JES account balance function help urgent!

Fromkidoman3@gmail.com
Date2013-03-26 03:30 -0700
SubjectJES account balance function help urgent!
Message-ID<b6aacd37-f010-4dc3-98ae-a1be39edd357@googlegroups.com>
I 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:
def setBalance(amount):
global balance
assert isinstance(amount,numbers.number)
balance = euros
printNow(balance)

Im not sure whats wrong, i only started programming a week ago, im so lost, please help me with this assignment
thnx

[toc] | [next] | [standalone]


#41878

FromDave Angel <davea@davea.name>
Date2013-03-26 06:56 -0400
Message-ID<mailman.3732.1364295392.2939.python-list@python.org>
In reply to#41874
On 03/26/2013 06:30 AM, kidoman3@gmail.com wrote:
> I 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:
> def setBalance(amount):
> global balance
> assert isinstance(amount,numbers.number)
> balance = euros
> printNow(balance)
>
> Im not sure whats wrong, i only started programming a week ago, im so lost, please help me with this assignment
> thnx
>

I'm not sure how literally to take your proposal.  You have no 
indentation in the function body, so that's one serious problem.  And 
you're apparently calling printNow() from within that function, which is 
NOT what was called for.  And the function takes "amount" as its 
parameter, but then uses 'euros' in the body.  That's a big spelling error.

You're also going to need to import numbers, if you want that isinstance 
to work.

The layout of your code should be something like:

shebang line (optional)
imports
global variables
def's
testing code (supplied by instructor)

Write all the functions, making sure each takes the expected parameters, 
even if the function does nothing more than print its name and 
parameters.  Then when the code runs, refine the function bodies till 
they're all correct.


-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web