python - having trouble adding multiple prices to a receipt -


im having trouble making receipt. supposed able take in multiple prices(as little 1 , many infinite(if u wanted go high)) , able subtotal of them, put tax on , total. cant figure out how add them multiple numbers up. keep getting (i had remove (<,>) , put these (",") show giving me.

when finished enter -1 enter price of item: 5.22 enter price of item: 6.35 enter price of item: -1 subtotal is:  "function subtotal @ 0x0314c9c0" tax is:  "function tax @ 0x0314c978" total is:  "function total @ 0x0314ca08" have bought 2 items thank shopping @ qmart 

and coding have far

print("qmart receipt".center(78, "-")) print("when finished enter -1")  def price(subtotal, items, price):     counter = 0     while counter <= items:         subtotal = (items + items)  def subtotal():     subtotal = sum(input) def tax():     tax = subtotal * .065 def total():     total = subtotal + tax   counter = 0 price = input("enter price of item: ")   while (true):     price = float(input("enter price of item: "))     counter += 1        if (price == -1):         print("your subtotal is: ", subtotal)         print("your tax is: ", tax)         print("your total is: ", total)         break;     print("you have bought", counter, "items") print("thank shopping @ qmart") 

first: use return statement return result -- assigning value local function you're doing means nothing in python.

so instead of

def subtotal():     subtotal = sum(input) def tax():     tax = subtotal * .065 def total():     total = subtotal + tax 

use:

def subtotal():     return sum(input) def tax():     return subtotal() * .065 def total():     return subtotal() + tax() 

second, , i've done in snippet above, call function without arguments, put () after name -- naming function not call it. applies prints towards end, -- you'll need put () after each function name you're calling.

edit: op asks show yet more fixes bugs they're "still little confused" (?!). explained in comment, change subtotal to:

def subtotal():     return sum(prices) 

(not using input, name of built-in function, name list of prices!); , change loop start

prices = [] while true:     price = float(input("enter price of item: "))     if price != -1: prices.append(price) 

i've removed useless variable counter -- use len(prices) instead in penultimate print.

putting these changes code op should have working program. no, op, before ask: i'm not going "putting together" on behalf -- please show evidence of some working neurons doing yourself:-)


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

Simple Angular 2 project fails 'Unexpected reserved word' -

php - Get process resource by PID -