# Trying to make a "total purchase calculator"

Page 1 of 1

## 2 Replies - 7458 Views - Last Post: 04 July 2012 - 12:06 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=284766&amp;s=83d36d245f6add9f84d641303c085a03&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mike316

Reputation: 0
• 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 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

• D.I.C Lover

Reputation: 2619
• Posts: 4,175
• 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

### #3 mike316

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

## Re: Trying to make a "total purchase calculator"

Posted 04 July 2012 - 12:06 PM

sepp2k, 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. I will try your idea about changing my function. Again thank so much