main() not running functions properly - python

def load():
global name
global count
global shares
global pp
global sp
global commission
name=input("Enter stock name OR -999 to Quit: ")
count =0
while name != '-999':
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
name=input("\nEnter stock name OR -999 to Quit: ")
totalpr=0
def calc():
global amount_paid
global amount_sold
global profit_loss
global commission_paid_sale
global commission_paid_purchase
global totalpr
amount_paid=shares*pp
commission_paid_purchase=amount_paid*commission
amount_sold=shares*sp
commission_paid_sale=amount_sold*commission
profit_loss=(amount_sold - commission_paid_sale) -(amount_paid + commission_paid_purchase)
totalpr=totalpr+profit_loss
def display():
print("\nStock Name:", name)
print("Amount paid for the stock: $", format(amount_paid, '10,.2f'))
print("Commission paid on the purchase: $", format(commission_paid_purchase, '10,.2f'))
print("Amount the stock sold for: $", format(amount_sold, '10,.2f'))
print("Commission paid on the sale: $", format(commission_paid_sale, '10,.2f'))
print("Profit (or loss if negative): $", format(profit_loss, '10,.2f'))
def main():
load()
calc()
display()
main()
print("\nTotal Profit is $", format(totalpr, '10,.2f'))
I need the main(): to call load(),calc() and display() in that order. However, the program stops after load. The output will merely loop the load without calc or print.
I have been instructed specifically to NOT place calc() and display() in the while loop block, tempting as that may be. Also note, that solves the problem but that is not the solution I am specifically looking for.
What do I need to do to make this program work properly?
OUTPUT SHOULD LOOK LIKE THIS:
Enter stock name OR -999 to Quit: APPLE
Enter number of shares: 10000
Enter purchase price: 400
Enter selling price: 800
Enter commission: 0.04
Stock Name: APPLE
Amount paid for the stock: $ 4,000,000.00
Commission paid on the purchase: $ 160,000.00
Amount the stock sold for: $ 8,000,000.00
Commission paid on the sale: $ 320,000.00
Profit (or loss if negative): $ 3,520,000.00
Enter stock name OR -999 to Quit: FACEBOOK
Enter number of shares: 10000
Enter purchase price: 5
Enter selling price: 500
Enter commission: 0.04
Stock Name: FACEBOOK
Amount paid for the stock: $ 50,000.00
Commission paid on the purchase: $ 2,000.00
Amount the stock sold for: $ 5,000,000.00
Commission paid on the sale: $ 200,000.00
Profit (or loss if negative): $ 4,748,000.00
Enter stock name OR -999 to Quit: -999
Total Profit is $ 14,260,000.00
HERE IS THE OUTPUT I AM GETTING(THAT I DO NOT WANT):
====== RESTART: C:\Users\Elsa\Desktop\Homework 3, Problem 1.py ======
Enter stock name OR -999 to Quit: YAHOO!
Enter number of shares: 10000
Enter purchase price: 10
Enter selling price: 100
Enter commission: 0.04
Enter stock name OR -999 to Quit: GOOGLE
Enter number of shares: 10000
Enter purchase price: 15
Enter selling price: 150
Enter commission: 0.03
Enter stock name OR -999 to Quit: -999
Stock Name: -999
Amount paid for the stock: $ 150,000.00
Commission paid on the purchase: $ 4,500.00
Amount the stock sold for: $ 1,500,000.00
Commission paid on the sale: $ 45,000.00
Profit (or loss if negative): $ 1,300,500.00
Total Profit is $ 1,300,500.00
>>>

I think this is the solution (one of many) you could probably take:
def load():
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
return shares, pp, sp, commission
def calc(totalpr, shares, pp, sp, commission):
amount_paid=shares*pp
commission_paid_purchase=amount_paid*commission
amount_sold=shares*sp
commission_paid_sale=amount_sold*commission
profit_loss=(amount_sold - commission_paid_sale) -(amount_paid + commission_paid_purchase)
totalpr=totalpr+profit_loss
return (amount_paid, commission_paid_purchase, amount_sold,
commission_paid_sale, profit_loss, totalpr)
def display(name, amount_paid, commission_paid_purchase,
amount_sold, commission_paid_sale, profit_loss):
print("\nStock Name:", name)
print("Amount paid for the stock: $", format(amount_paid, '10,.2f'))
print("Commission paid on the purchase: $", format(commission_paid_purchase, '10,.2f'))
print("Amount the stock sold for: $", format(amount_sold, '10,.2f'))
print("Commission paid on the sale: $", format(commission_paid_sale, '10,.2f'))
print("Profit (or loss if negative): $", format(profit_loss, '10,.2f'))
def main():
totalpr = 0
name=input("Enter stock name OR -999 to Quit: ")
while name != '-999':
shares, pp, sp, commission = load()
am_paid, com_paid_purch, am_sold, \
com_paid_sale, profit_loss, totalpr = calc(totalpr, shares, pp, sp, commission)
display(name, am_paid, com_paid_purch,
am_sold, com_paid_sale, profit_loss)
name=input("Enter stock name OR -999 to Quit: ")
return totalpr
totalpr = main()
print("\nTotal Profit is $", format(totalpr, '10,.2f'))

Related

Display a list of items without using a list

I am trying to create a program that inputs the price and tax rate and returns the item number, price, tax rate, and item price in an orderly format.
Here is the criteria:
The user can enter multiple items until the user says otherwise.
It calculates and display the total amount of purchased items on the bottom.
The price gets a 3% discount if the total amount is 1000 or more
I am not allowed to use arrays to solve this problem and I must separate the inputs from the outputs on the screen.
An example output is shown here:
Enter the price: 245.78
Enter the tax rate: 12
Are there any more items? (y/n) y
Enter the price: 34
Enter the tax rate: 10
Are there any more items? (y/n) y
Enter the price: 105.45
Enter the tax rate: 7
Are there any more items? (y/n) n
Item Price Tax Rate % Item Price
====================================
1 245.78 12% 275.27
2 34.00 10% 37.40
3 105.45 7% 112.83
Total amount: $425.51
Here is my code so far:
price= float(input('Enter the price: '))
taxRate= float(input('Enter the tax rate: '))
itemPrice = price * (1 + taxRate/100)
acc= 0
while True:
query=input('Are there any more items? (y/n)')
if query== 'y':
price= float(input('Enter the price: '))
taxRate= float(input('Enter the tax rate: '))
itemPrice = price * (1 + taxRate/100)
print(itemPrice )
acc+=1
elif query=='n':
break
print ("Item Price Tax Rate% Item Price")
print ("=========================================")
print( (acc+1) , format(price,'10.2f'), format(taxRate,'10.2f') ,
format(itemPrice,'14.2f') )
for num in range(0,acc):
print (acc, price, taxRate, itemPrice)
The output is shown as this:
Enter the price: 245.78
Enter the tax rate: 12
Are there any more items? (y/n)y
Enter the price: 34
Enter the tax rate: 10
37.400000000000006
Are there any more items? (y/n)y
Enter the price: 105.45
Enter the tax rate: 7
112.8315
Are there any more items? (y/n)n
Item Price Tax Rate% Item Price
=========================================
3 105.45 7.00 112.83
2 105.45 7.0 112.8315
2 105.45 7.0 112.8315
I just have a hard time trying to do this without using an array.. can anyone be of assistance?
You could build a string as a buffer for the output?
Like this:
out = ""
acc = 0
totalAmount = 0
query = 'y'
while query == 'y':
price = float(input('Enter the price: '))
taxRate = float(input('Enter the tax rate: '))
itemPrice = price * (1 + taxRate/100)
acc += 1
totalAmount += itemPrice
out += f"{acc:>4} {price:9.2f} {taxRate:11.2f}% {itemPrice:13.2f}\n"
query = input('Are there any more items? (y/n) ')
print("Item Price Tax Rate% Item Price")
print("=========================================")
print(out)
print(f"Total amount: ${totalAmount:.2f}")
if totalAmount >= 1000:
print(" Discount: 3%")
print(f"Total amount: ${totalAmount*0.97:.2f} (after discount)")

Loop function for a check out program in python

My teacher wants this code to run on a loop but I am not sure how to do that. Can anyone help me please?
ask = input("Enter only one name of the item bought like Potatoes, Ham, AppleJuice, or Gatorade: ")
if ask == "potatoes":
def potatoes (quantity, price=5.99):
total = quantity * price
while True:
if quantity > 15:
print("Congratulations, you are eligible for 11% discount")
totalWithDiscount = total - (0.08 * total)
print("your total with 8% discount and no tax: $", totalWithDiscount)
print("Visit us soon!!")
return (0.879 * totalWithDiscount) + totalWithDiscount
else:
print("sorry, you are not eligible for 11% discount")
print("your total with 11% discount and no tax: $", total)
return (0.879 * total) + total
print("Sorry, you are only eligible for discount, if you buy more than 15 Lbs. of Potatoes. ")
print("Total without discount and no Tax $", total)
print("Your Total with Tax: 5.29% is $", tax3)
print("Thank you, for being Walmart' Valuable Shopper.")
print("Visit us soon!!")
potatoes(int(input("Enter the quantity of Potatoes you bought : ")), 8.99)
Your code is very wrong and it will not run, but I have an idea of what you are trying to do, so this will work
def potatoes (quantity, price=5.99):
total = quantity * price
if quantity > 15:
print("Congratulations, you are eligible for 11% discount")
totalWithDiscount = total - (0.08 * total)
print("your total with 8% discount and no tax: $", totalWithDiscount)
print("Visit us soon!!")
return (0.879 * totalWithDiscount) + totalWithDiscount
else:
print("sorry, you are not eligible for 11% discount")
print("your total with 11% discount and no tax: $", total)
tax3 = (0.879 * total) + total
print("Sorry, you are only eligible for discount, if you buy more than 15 Lbs. of Potatoes. ")
print("Total without discount and no Tax $", total)
print("Your Total with Tax: 5.29% is $", tax3)
print("Thank you, for being Walmart' Valuable Shopper.")
print("Visit us soon!!")
while True:
ask = input("Enter only one name of the item bought like Potatoes, Ham, AppleJuice, or Gatorade: ")
if ask == "potatoes":
number_of_potatoes = int(input("Enter the quantity of Potatoes you bought : "))
potatoes(number_of_potatoes, 8.99)
else:
print('Thank you visiting')
break
Your code is a little bit confusing but i hope this is what you intended for.
1.I moved the function definition out of the loop, and it is inside the loop that you call it so the code inside the function can be reused as many times as you need!
2.I also changed the loop condition for when the user inserts "no" so there's an end to it, but change for whatever you want
3.About the return statement it's important to remember that when it's executed the function that it is within ends and return the designated value, everything after it won't be executed, that's why i moved it to the end.
4.And finally there's a variable tax3 that isn't being defined anywhere in your code, maybe you didn't put it here or maybe you just forgot about it, so you need to fix it or delete it so the code works. Hope i understood your question, good programming!
def potatoes (quantity, price=5.99):
total = quantity * price
if quantity > 15:
print("Congratulations, you are eligible for 11% discount")
totalWithDiscount = total - (0.08 * total)
print("your total with 8% discount and no tax: $", totalWithDiscount)
print("Visit us soon!!")
return (0.879 * totalWithDiscount) + totalWithDiscount
else:
print("sorry, you are not eligible for 11% discount")
print("your total with 11% discount and no tax: $", total)
print("Sorry, you are only eligible for discount, if you buy more than 15 Lbs. of Potatoes. ")
print("Total without discount and no Tax $", total)
print("Your Total with Tax: 5.29% is $", tax3)
print("Thank you, for being Walmart' Valuable Shopper.")
print("Visit us soon!!")
return (0.879 * total) + total
ask = input("Enter only one name of the item bought like Potatoes, Ham, AppleJuice, or Gatorade: ")
while(ask != "no"):
if ask == "potatoes":
potatoes(int(input("Enter the quantity of Potatoes you bought : ")), 8.99)
ask = input("Enter only one name of the item bought like Potatoes, Ham, AppleJuice, or Gatorade: ")

Need main to call functions in order, properly

def load():
global name
global count
global shares
global pp
global sp
global commission
name=input("Enter stock name OR -999 to Quit: ")
count =0
while name != '-999':
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
name=input("\nEnter stock name OR -999 to Quit: ")
totalpr=0
def calc():
global amount_paid
global amount_sold
global profit_loss
global commission_paid_sale
global commission_paid_purchase
global totalpr
amount_paid=shares*pp
commission_paid_purchase=amount_paid*commission
amount_sold=shares*sp
commission_paid_sale=amount_sold*commission
profit_loss=(amount_sold - commission_paid_sale) -(amount_paid + commission_paid_purchase)
totalpr=totalpr+profit_loss
def display():
print("\nStock Name:", name)
print("Amount paid for the stock: $", format(amount_paid, '10,.2f'))
print("Commission paid on the purchase: $", format(commission_paid_purchase, '10,.2f'))
print("Amount the stock sold for: $", format(amount_sold, '10,.2f'))
print("Commission paid on the sale: $", format(commission_paid_sale, '10,.2f'))
print("Profit (or loss if negative): $", format(profit_loss, '10,.2f'))
def main():
load()
calc()
display()
main()
print("\nTotal Profit is $", format(totalpr, '10,.2f'))
I need the main(): to call load(),calc() and display() in that order. However, the program stops after load. The output will merely loop the load without calc or print.
I have been instructed specifically to NOT place calc() and display() in the while loop block, tempting as that may be. Also note, that solves the problem but that is not the solution I am specifically looking for.
What do I need to do to make this program work properly?
OUTPUT SHOULD LOOK LIKE THIS:
Enter stock name OR -999 to Quit: APPLE
Enter number of shares: 10000
Enter purchase price: 400
Enter selling price: 800
Enter commission: 0.04
Stock Name: APPLE
Amount paid for the stock: $ 4,000,000.00
Commission paid on the purchase: $ 160,000.00
Amount the stock sold for: $ 8,000,000.00
Commission paid on the sale: $ 320,000.00
Profit (or loss if negative): $ 3,520,000.00
Enter stock name OR -999 to Quit: FACEBOOK
Enter number of shares: 10000
Enter purchase price: 5
Enter selling price: 500
Enter commission: 0.04
Stock Name: FACEBOOK
Amount paid for the stock: $ 50,000.00
Commission paid on the purchase: $ 2,000.00
Amount the stock sold for: $ 5,000,000.00
Commission paid on the sale: $ 200,000.00
Profit (or loss if negative): $ 4,748,000.00
Enter stock name OR -999 to Quit: -999
Total Profit is $ 14,260,000.00
HERE IS THE OUTPUT ERROR I AM GETTING:
====== RESTART: C:\Users\Elsa\Desktop\Homework 3, Problem 1.py ======
Enter stock name OR -999 to Quit: YAHOO!
Enter number of shares: 10000
Enter purchase price: 10
Enter selling price: 100
Enter commission: 0.04
Enter stock name OR -999 to Quit: GOOGLE
Enter number of shares: 10000
Enter purchase price: 15
Enter selling price: 150
Enter commission: 0.03
Enter stock name OR -999 to Quit: -999
Stock Name: -999
Amount paid for the stock: $ 150,000.00
Commission paid on the purchase: $ 4,500.00
Amount the stock sold for: $ 1,500,000.00
Commission paid on the sale: $ 45,000.00
Profit (or loss if negative): $ 1,300,500.00
Total Profit is $ 1,300,500.00
>>>
The first problem is that you are clobbering the variable name every time you execute the input statement. You need to assign the result of input to temporary variable and check that for equality to -999, like this:
def load():
global name
global count
global shares
global pp
global sp
global commission
count =0
while True:
s=input("Enter stock name OR -999 to Quit: ")
if s == '-999':
break
name = s
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
Now when the function returns, the value of name will be a valid stock name.
The second problem is that your teacher has apparently instructed you not to do the very thing that you need to do in order to make your program work. If you can't put the functions that you need to call inside a loop, they can only run once. In that case it is logically impossible to get a separate printout for each stock. I can't help you with that.
Based on your comment
take the calc() and display() inside the loop and move them directly into def main():
this is consistent with your expected output:
def main():
name=input("Enter stock name OR -999 to Quit: ")
count, totalpr = 0, 0
while name != '-999':
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
# calculation
amount_paid=shares*pp
commission_paid_purchase=amount_paid*commission
amount_sold=shares*sp
commission_paid_sale=amount_sold*commission
profit_loss=(amount_sold - commission_paid_sale) -(amount_paid + commission_paid_purchase)
totalpr=totalpr+profit_loss
# printing
print("\nStock Name:", name)
print("Amount paid for the stock: $", format(amount_paid, '10,.2f'))
print("Commission paid on the purchase: $", format(commission_paid_purchase, '10,.2f'))
print("Amount the stock sold for: $", format(amount_sold, '10,.2f'))
print("Commission paid on the sale: $", format(commission_paid_sale, '10,.2f'))
print("Profit (or loss if negative): $", format(profit_loss, '10,.2f'))
# next loop
name=input("\nEnter stock name OR -999 to Quit: ")
print("\nTotal Profit is $", format(totalpr, '10,.2f'))
It seems like an exercise in refactoring - moving function together into a single function.

Output is blank

def load():
name=0
count=0
totalpr=0
name=input("Enter stock name OR -999 to Quit: ")
while name != '-999':
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
name=input("Enter stock name OR -999 to Quit: ")
def calc():
amount_paid=shares*pp
commission_paid_purchase=amount_paid*commission
amount_sold=shares*sp
commission_paid_sale=amount_sold*commission
profit_loss=(amount_sold - commission_paid_sale) -(amount_paid + commission_paid_purchase)
totalpr=totalpr+profit_loss
def print():
print("\nStock Name:", name)
print("Amount paid for the stock: $", format(amount_paid, '10,.2f'))
print("Commission paid on the purchase: $", format(commission_paid_purchase, '10,.2f'))
print("Amount the stock sold for: $", format(amount_sold, '10,.2f'))
print("Commission paid on the sale: $", format(commission_paid_sale, '10,.2f'))
print("Profit (or loss if negative): $", format(profit_loss, '10,.2f'))
print("Total Profit is $", format(totalpr, '10,.2f'))
def main():
load()
calc()
print()
I want to write the main() function to call the functions above it.
However, when I run the program, the output is blank - nothing - there is no error given to elucidate the problem.
What am I doing wrong?
Along with the problem of using built-in function, you've scope problem too. So, you must make the variables defined in each function global so that they can be assessed in other functions.
def load():
global name
global count
global shares
global pp
global sp
global commission
name=input("Enter stock name OR -999 to Quit: ")
count =0
while name != '-999':
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
name=input("Enter stock name OR -999 to Quit: ")
def calc():
global amount_paid
global amount_sold
global profit_loss
global commission_paid_sale
global commission_paid_purchase
global totalpr
totalpr=0
amount_paid=shares*pp
commission_paid_purchase=amount_paid*commission
amount_sold=shares*sp
commission_paid_sale=amount_sold*commission
profit_loss=(amount_sold - commission_paid_sale) -(amount_paid + commission_paid_purchase)
totalpr=totalpr+profit_loss
def display():
print("\nStock Name:", name)
print("Amount paid for the stock: $", format(amount_paid, '10,.2f'))
print("Commission paid on the purchase: $", format(commission_paid_purchase, '10,.2f'))
print("Amount the stock sold for: $", format(amount_sold, '10,.2f'))
print("Commission paid on the sale: $", format(commission_paid_sale, '10,.2f'))
print("Profit (or loss if negative): $", format(profit_loss, '10,.2f'))
print("Total Profit is $", format(totalpr, '10,.2f'))
def main():
load()
calc()
display()
main()
To run a python module as a program, you should run it like the below one. In your program main is just like other functions and won't be executed automatically.
if __name__ == '__main__':
load()
calc()
print()
What we are doing is, we check if the module name is __main__ and we call other functions. __main__ is set only when we run the module as a main program.
You are not calling main() & also change print() function name, here I have changed it to fprint()
def load():
name=0
count=0
totalpr=0
name=input("Enter stock name OR -999 to Quit: ")
while name != '-999':
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
name=input("Enter stock name OR -999 to Quit: ")
def calc():
amount_paid=shares*pp
commission_paid_purchase=amount_paid*commission
amount_sold=shares*sp
commission_paid_sale=amount_sold*commission
profit_loss=(amount_sold - commission_paid_sale) -(amount_paid + commission_paid_purchase)
totalpr=totalpr+profit_loss
def fprint():
print("\nStock Name:", name)
print("Amount paid for the stock: $", format(amount_paid, '10,.2f'))
print("Commission paid on the purchase: $", format(commission_paid_purchase, '10,.2f'))
print("Amount the stock sold for: $", format(amount_sold, '10,.2f'))
print("Commission paid on the sale: $", format(commission_paid_sale, '10,.2f'))
print("Profit (or loss if negative): $", format(profit_loss, '10,.2f'))
print("Total Profit is $", format(totalpr, '10,.2f'))
def main():
load()
calc()
fprint()
main()
edit: changed function name of print()

I am getting a name error for the following input stocks using functions

def main():
def input_stocks():
tot_pr = 0
while True:
stock_name = input("\nEnter Stock Name: ")
shares_bought = float(input("\nNumber of Shares bought: "))
stock_pp = float(input("Enter stock purchasing price: "))
stock_sp = float(input("Enter stock selling price: "))
commision = float(input("Enter broker Commision: "))
peaceout = input("Continue or exit? (case sensitive):")
if peaceout == 'quit':
return stock_name,shares_bought,stock_pp,stock_sp,commision
def calc():
amount_paid = shares_bought * stock_pp
paid_commision_bought = amount_paid * commision
stock_sold = shares_bought * stock_sp
paid_commision_sold = stock_sold * commision
pl = (stock_sold - paid_commision_sold) - (amount_paid + paid_commision_bought)
tot_pr = tot_pr + pl
def output():
print("\nStock Name:", stock_name)
print("Amount paid: $", format(amount_paid,',.2f'))
print("Paid commision bought: $", format(paid_commision_bought,',.2f'))
print("Stock sold $", format(stock_sold,',.2f'))
print("Paid commision sold: $", format(paid_commision_sold,',.2f'))
print("Profit or Loss: $", format(pl,',.2f'))
print("Total Profit thus far: $", format(tot_pr,',.2f'))
return stock_name,amount_paid,paid_commision_bought,paid_commision_sold,pl,tot_pr
output()
main()
>
NameError: name 'stock_name' is not defined (I'd assume others won't be defined as well...
What can I do to fix this error, and how can I prevent this in the future? I am quite new to this so I want to learn from my mistakes
stock_name and the other variables in output() will not be defined until the input_stocks() function is actually run. Just defining a function does not actually run it.
def load():
tot_pr = 0
peaceout = ''
while peaceout != 'exit':
stock_name = input("\nEnter Stock Name: ")
shares_bought = float(input("\nNumber of Shares bought: "))
stock_pp = float(input("Enter stock purchasing price: "))
stock_sp = float(input("Enter stock selling price: "))
commision = float(input("Enter broker Commision: "))
peaceout = input("Continue or exit? (case sensitive):")
return stock_name,shares_bought,stock_pp,stock_sp,commision,tot_pr
def calc(shares_bought,stock_pp,stock_sp,commision,tot_pr):
amount_paid = shares_bought * stock_pp
paid_commision_bought = amount_paid * commision
stock_sold = shares_bought * stock_sp
paid_commision_sold = stock_sold * commision
pl = (stock_sold - paid_commision_sold) - (amount_paid + paid_commision_bought)
tot_pr = tot_pr + pl
return amount_paid,paid_commision_bought,stock_sold,paid_commision_sold,pl,tot_pr
def output(stock_name,amount_paid,paid_commision_bought,stock_sold,paid_commision_sold,pl,tot_pr):
print("\nStock Name:", stock_name)
print("Amount paid: $", format(amount_paid,',.2f'))
print("Paid commision bought: $", format(paid_commision_bought,',.2f'))
print("Stock sold $", format(stock_sold,',.2f'))
print("Paid commision sold: $", format(paid_commision_sold,',.2f'))
print("Profit or Loss: $", format(pl,',.2f'))
print("Total Profit thus far: $", format(tot_pr,',.2f'))
return stock_name,amount_paid,paid_commision_bought,paid_commision_sold,pl,tot_pr
def main():
stock_name,shares_bought,stock_pp,stock_sp,commision,tot_pr = load()
amount_paid,paid_commision_bought,stock_sold,paid_commision_sold,pl,tot_pr = calc(shares_bought,stock_pp,stock_sp,commision,tot_pr)
output(stock_name,amount_paid,paid_commision_bought,stock_sold,paid_commision_sold,pl,tot_pr)
main()
I rewrote my program, and the only problem now is it won't loop if I type in continue?
#Joran Beasley
#MattDMo

Categories