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():
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()
Immediately after commission is entered, the program should run the calculations and display the information accordingly. But right now, it's simply looping and not displaying/calculating anything.
I would like to maintain the structure of program itself --
def main():
load()
calc()
display()
But there is something else impeding the program from carrying the results of load into calc and then into display in that order.
My inexperienced (this is for a class) thought? It might be something with kicking out of the while loop after the stock information is loaded. There isn't (in my opinion) anything telling the program to move onto calc() and then move onto display()...I thought it was being achieved with the def main(): sequence but I could be wrong.
This is what the output should look like:
============== RESTART: C:\Users\ELSSAAAAA\Desktop\Sample.py ==============
Enter stock name OR -999 to Quit: GOOGLE
Enter number of shares: 10000
Enter purchase price: 30
Enter selling price: 300
Enter commission: 0.04
Stock Name: GOOGLE
Amount paid for the stock: $ 300,000.00
Commission paid on the purchase: $ 12,000.00
Amount the stock sold for: $ 3,000,000.00
Commission paid on the sale: $ 120,000.00
Profit (or loss if negative): $ 2,568,000.00
Enter stock name OR -999 to Quit: AMAZON
Enter number of shares: 10000
Enter purchase price: 25
Enter selling price: 250
Enter commission: 0.04
Stock Name: AMAZON
Amount paid for the stock: $ 250,000.00
Commission paid on the purchase: $ 10,000.00
Amount the stock sold for: $ 2,500,000.00
Commission paid on the sale: $ 100,000.00
Profit (or loss if negative): $ 2,140,000.00
Enter stock name OR -999 to Quit: -999
Total Profit is $ 14,260,000.00