i have write program has user input stock information, calculate variables, , spit out in while loop. keep getting error:
nameerror: name 'bc' not defined
for line
amt_paidcomm_onpurch,sold_for,comm_onsale,profit_loss = calc(shares,pp,sp,bc)
here code:
def load(): shares = int(input("enter number of shares: ")) pp = float(input("enter purchase price: ")) sp = float(input("enter selling price: ")) bc = float(input("enter commission: ")) print("\n") return shares, pp, sp, bc def calc(shares,pp,sp,bc): amt_paid = shares * pp comm_onpurch = amt_paid * bc sold_for = shares * sp comm_onsale = sold_for * bc profit_loss = (sold_for - comm_onsale) - (amt_paid + comm_onpurch) return amt_paid, comm_onpurch, sold_for,comm_onsale,profit_loss def output(name, amt_paid, comm_onpurch, sold_for,comm_onsale,profit_loss): print("stock name: ", name, "\n") print("amount paid stock: $", format(amt_paid, ',.2f')) print("commission paid on purchase: $", format(comm_onpurch, ',.2f')) print("amount stock sold for: $", format(sold_for, ',.2f')) print("commission paid on sale: $", format(comm_onsale, ',.2f')) print("profit or loss (if negative): $", format(profit_loss, ',.2f')) print('\n') def main(): total=0.0 name=input('enter stock name or -999 quit: ') while name != '-999': shares,pp,sp,rate=load() amt_paidcomm_onpurch,sold_for,comm_onsale,profit_loss = calc(shares,pp,sp,bc) output(name,amt_paid,comm_onpurch,sold_for,comm_onsale,profit_loss) total=total+profit_loss name=input("enter stock name or -999 quitz: ") print(total) main()
thank you!!
when call load()
assign variable bc
name rate
. either assign name bc
or change calling of calc
function use rate
instead.
i.e. @ moment have:
shares,pp,sp,rate=load() amt_paidcomm_onpurch,sold_for,comm_onsale,profit_loss = calc(shares,pp,sp,bc)
but want like:
shares,pp,sp,bc=load() amt_paidcomm_onpurch,sold_for,comm_onsale,profit_loss = calc(shares,pp,sp,bc)
or:
shares,pp,sp,rate=load() amt_paidcomm_onpurch,sold_for,comm_onsale,profit_loss = calc(shares,pp,sp,rate)
Comments
Post a Comment