2 Replies - 1472 Views - Last Post: 04 July 2012 - 12:06 PM Rate Topic: -----

#1 mike316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-July 12

Trying to make a "total purchase calculator"

Posted 04 July 2012 - 11:21 AM

I'm trying to make a purchase calculator in python. I defined my varibles and such, I enter in the cost of two items, then I want to figure out the subtotal, I then figure out the tax which is 6 percent, then I want to figure out the grand total of all the item with tax included. When I get to the grand total, it's adding more money then it's supposed too. Everything else works great, it's the grand total that's giving me the headache :online2long: I bought this Python book and just want to learn more about programming, I really enjoy it I'm just stuck. Thanks for helping and taking the time to read this post. I've attached a file of the program in case I post the code wrong.

def item():
    item = input('Enter the cost of item one ')
    item_two = input('Enter the cost of item two ')
    subtotal(item,item_two)
    tax(item,item_two)
    grand_total(item,item_two)
    

def subtotal(item,item_two):
    subtotal = item + item_two
    print 'The subtotal of the items is %.2f ' % subtotal

def tax(item,item_two):
    tax = .06 * (item + item_two)
    print 'The tax for the items is %.2f ' % tax

def grand_total(item,item_two):
    grand_total = (.06*item + item_two) + (item + item_two)
    print 'The total for your items is %.2f ' % grand_total

item ()



Is This A Good Question/Topic? 0
  • +

Replies To: Trying to make a "total purchase calculator"

#2 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2016
  • View blog
  • Posts: 3,043
  • Joined: 21-June 11

Re: Trying to make a "total purchase calculator"

Posted 04 July 2012 - 11:43 AM

In line 14 you're parenthesizing item + item_two because otherwise the .06 * would only apply to the first item. In line 18 you forgot to do this (or you misplaces the opening parenthesis).

PS: If you changed your functions to return the calculated value rather than printing it, you could have implemented grand_total by simply calling tax and subtotal and adding their results. That would have been cleaner code and it would have avoided the mistake in the process.

This post has been edited by sepp2k: 04 July 2012 - 11:45 AM

Was This Post Helpful? 0
  • +
  • -

#3 mike316  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-July 12

Re: Trying to make a "total purchase calculator"

Posted 04 July 2012 - 12:06 PM

View Postsepp2k, on 04 July 2012 - 11:43 AM, said:

In line 14 you're parenthesizing item + item_two because otherwise the .06 * would only apply to the first item. In line 18 you forgot to do this (or you misplaces the opening parenthesis).

PS: If you changed your functions to return the calculated value rather than printing it, you could have implemented grand_total by simply calling tax and subtotal and adding their results. That would have been cleaner code and it would have avoided the mistake in the process.


Thank you so much for your help. It works now. :clap: I will try your idea about changing my function. Again thank so much
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1