[Tutor] sales tax

Michael Langford mlangford.cs03 at gtalumni.org
Wed Sep 19 03:34:29 CEST 2007


This function can easily found using the google programming rule:

I want a function that does 'action'

Type: <Name of programming language> <action> into google

Look in top 5 results. If that doesn't work, try synonyms for 'action'

     --Michael

PS: The function you're looking for is called round. Its first param is the
number to round, the seconds is how many digits past the radix point to
keep.

-- 
Michael Langford
Phone: 404-386-0495
Consulting: http://www.TierOneDesign.com/
Entertaining: http://www.ThisIsYourCruiseDirectorSpeaking.com

On 9/18/07, Christopher Spears <cspears2002 at yahoo.com> wrote:
>
> I wrote a script that takes a price and a sales tax
> and calculates the new price.
>
> #!/usr/bin/env python
>
> def calculate_price(price, percent_tax):
>     sales_tax = price * percent_tax
>     new_price = price + sales_tax
>     return new_price
>
> price = float(raw_input("Enter a price: "))
> percent_tax = float(raw_input("Enter a sales tax: "))
> print "%.2f" % calculate_price(price, percent_tax)
>
> Here is the script in action:
> io at io-station-1 ./chap5 173> python sales_tax.py
> Enter a price: 10.00
> Enter a sales tax: .0825
> 10.82
>
> I'm not convinced that the new price is completely
> accurate because the price without the string
> formating is 10.825
>
> io at io-station-1 ./chap5 164> python sales_tax.py
> Enter a price: 10
> Enter a sales tax: .0825
> 10.825000
>
> Wouldn't the price be rounded up to 10.83 in the real
> world?  How can I accomplish this?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070918/08bb3c3b/attachment.htm 


More information about the Tutor mailing list