Question

(PYTHON) Stock Transaction Program Last month Joe purchased some stock from StockTrade.   1. Write a function(s)...

(PYTHON) Stock Transaction Program

Last month Joe purchased some stock from StockTrade.  

1. Write a function(s) to allow

the user to input the followings:

·The name of the stock

·Number of shares Joe bought

· Stock purchase price

· Stock selling price

·Broker commission

2. Write function(s) to calculate: and:

· The amount of money Joe paid for the stock (number of shares bought * purchase price)

· The amount of commission Joe paid his broker when he bought the stock. (Amount he paid for stocks* commission in percent)

·The amount that Jim sold the stock for. (number of shares * selling price)

·The amount of commission Joe paid his broker when he sold the

stock. (Amount he sold shares * commission in percent)

· Calculate the amount of money Joe had left when he sold the stock and paid his broker (both times). If this amount is positive, then Joe made a profit. If the amount is negative, then Jim lost money.

· Profit/loss =(amount paid to buy stocks + commission) – (amount for sold stocks– commission)

3. Write function(s) to display the following paid for the stock(s) that Joe had transacted ( if Joe entered 5 sets of stocks transactions then output 5 sets of stocks).

·The Name of the Stock

·The amount of money Joe paid for the stock (number of shares bought * purchase price)

·The amount of commission Joe paid his broker when he bought the stock. (Amount he paid for stocks* commission in percent)

· The amount that Jim sold the stock for. (number of shares * selling price)

·The amount of commission Joe paid his broker when he sold the stock. (Amount he sold shares * commission in percent)

· Display the amount of money Joe had left when he sold the stock and paid his broker (both times). If this amount is positive, then Joe made a profit. If the amount is negative, then Jim lost money.

Profit/loss =(amount paid to buy stocks + commission) – (amount for sold stocks– commission)

4. Write the main() function to call the above functions. You should also allow the user to enter as many stocks as he/she wants or not to enter any stock at all

.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#User input method

def userInput():

    #Getting stock name

    stockName = input("Enter the name of the stock: ")

    #Getting number of stocks with error check

    numberOfStocks = int(input("Enter the number of stocks bought: "))

    while(numberOfStocks < 0):

        print("ERROR!!!!Number of stocks bought should be positive.")

        numberOfStocks = int(input("Enter the number of stocks bought: "))

    #Getting purchase price with error check

    stockPurchasePrice = float(input("Enter purchase price: "))

    while(stockPurchasePrice < 0):

        print("ERROR!!!!Price should be positive.")

        stockPurchasePrice = float(input("Enter purchase price: "))

    #Getting selling price with error check

    stockSellingPrice = float(input("Enter selling price: "))

    while(stockSellingPrice < 0):

        print("ERROR!!!!Price should be positive.")

        stockSellingPrice = float(input("Enter selling price: "))

    #Getting broker commission and error check

    brokerCommission = float(input("Enter broker commission percentage: "))

    while(brokerCommission < 0):

        print("ERROR!!!!Commission percentage should be positive.")

        brokerCommission = float(input("Enter broker commission percentage: "))

    return stockName, numberOfStocks, stockPurchasePrice, stockSellingPrice, brokerCommission

   

#Method to calculate profit / loss

def calculate(numberOfStocks, stockPurchasePrice, stockSellingPrice, brokerCommission):

    totalPurchasePrice = (numberOfStocks * stockPurchasePrice)

    brokerPurchaseCharge = totalPurchasePrice * (brokerCommission / 100)

    totalSellingPrice = (numberOfStocks * stockSellingPrice)

    brokerSellingCharge = totalSellingPrice * (brokerCommission / 100)

    profitORloss = (totalSellingPrice - brokerSellingCharge) - (totalPurchasePrice + brokerPurchaseCharge)

    return totalSellingPrice, brokerSellingCharge, totalPurchasePrice, brokerPurchaseCharge, profitORloss

   

#method to display

def display(stockNumber, stockName, totalSellingPrice, brokerSellingCharge, totalPurchasePrice, brokerPurchaseCharge, profitORloss):

    print("\nStock %i"%stockNumber)

    print("Puchase Amount                     = $%.2f"%totalPurchasePrice)

    print("Broker Commission For Purchase     = $%.2f"%brokerPurchaseCharge)

    print("Selling Amount                     = $%.2f"%totalSellingPrice)

    print("Broker Commission For Selling      = $%.2f"%brokerSellingCharge)

    print("Amount Left In Hand                = $%.2f"%profitORloss)

    if(profitORloss<0):

        print(stockName + " got loss of $%.2f"%( - 1 * profitORloss) + " amount")

    else:

        print(stockName + " got profit of $%.2f"%profitORloss + " amount\n")

       

#Main method

def main():

    #Stock details storing lists

    stockNames = []

    shareCount = []

    stockPurchasePrices = []

    stockSellingPrices = []

    commissions = []

    #get the number of stock details enter and error check

    stockNumbers = int(input("\nPlease enter the number of stock details are you going to enter: "))

    while(stockNumbers < 0):

        print("ERROR!!!Please enter positive value.")

        stockNumbers = int(input("Please enter the number of stock details are you going to enter: "))

    #Loop to get details

    for i in range(0, stockNumbers):

        name, count, price1, price2, commision = userInput()

        stockNames.append(name)

        shareCount.append(count)

        stockPurchasePrices.append(price1)

        stockSellingPrices.append(price2)

        commissions.append(commision)

    #Calculate and print

    for i in range(0, stockNumbers):

        purchaseAmount, purchaseCommission, sellingAmount, sellingCommission, profitORloss = calculate(shareCount[i], stockPurchasePrices[i], stockSellingPrices[i], commissions[i])

        display(i + 1, stockNames[i], purchaseAmount, purchaseCommission, sellingAmount, sellingCommission, profitORloss)

if __name__ == "__main__":

    main()

+ code.py t o co on WNH |- |- | #User input method def user Input(): #Getting stock name stockName = input (Enter the name ocode.py x 36 #method to display 37 def display (stockNumber, stockName, totalSelling Price, brokerSellingCharge, totalPurchas

Output

MOLI UISLUR detalls are you going to enter: 2 Enter the name of the stock: StockA Enter the number of stocks bought: 200 Ente

Add a comment
Know the answer?
Add Answer to:
(PYTHON) Stock Transaction Program Last month Joe purchased some stock from StockTrade.   1. Write a function(s)...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 10. Stock Transaction Program 18pts Last month Joe purchased some stock in Acme Software, Inc. Here...

    10. Stock Transaction Program 18pts Last month Joe purchased some stock in Acme Software, Inc. Here are the details of the purchase: • The number of shares that Joe purchased was 1,000. • When Joe purchased the stock, he paid $32.87 per share. • Joe paid his stockbroker a commission that amounted to 2 percent of the amount he paid for the stock. Two weeks later Joe sold the stock. Here are the details of the sale: • The number...

  • Last month Joe purchased some stock in Acme Software, Inc. Here are the details of the...

    Last month Joe purchased some stock in Acme Software, Inc. Here are the details of the purchase: The number of shares that Joe purchased was 1,000. When Joe purchased the stock, he paid $45.50 per share. Joe paid his stockbroker a commission that amounted to 2% of the amount he paid for the stock Two weeks later Joe sold the stock. Here are the details of the sale: The number of shares that Joe sold was 1,000. He sold the...

  • Problem Statement Last month Tian purchased some stock in Acme Software, Inc. Here are the details...

    Problem Statement Last month Tian purchased some stock in Acme Software, Inc. Here are the details of the purchase:  The number of shares that Tian purchased was 1,000  When Tian purchased the stock, he paid $33.92 per share  Tian paid his stockbroker a commission that amounted to 2% of the amount he paid for the stock. One week later, Tian sold the stock. Here are the details of the sale: The number of shares sold was 1,000...

  • Please take a screenshot or picture of work done in the PYTHON SHELL to see steps....

    Please take a screenshot or picture of work done in the PYTHON SHELL to see steps. Thank you. • Make sure to test your program before submit. Last month, Joe purchased some stock in Acme Software, Inc. Here are the details of the purchase: • The number of shares that Joe purchased was 2000. • When Joe purchased the stock, he paid $40.00 per share. • Joe paid his stockbroker a commission that amounted to 3 percent of the amount...

  • Please use C++ only CSIT163 Project 1 - Taking Stock Recently, Joe Btfsplk purchased some stock...

    Please use C++ only CSIT163 Project 1 - Taking Stock Recently, Joe Btfsplk purchased some stock in Acme Software, Inc. The details of the purchase are as follows: • 1,000 shares at $32.87 per share. • The stockbroker received $5 dollars plus a commission of 2% of the total purchase. Should he decide to sell, the stockbroker receives $5 dollars plus a commission of 2% of the total sale. Feeling jittery, Joe is considering selling the stock. The only thing...

  • With a partner, use the problem solving approach covered on day 1. Write out an algorithm...

    With a partner, use the problem solving approach covered on day 1. Write out an algorithm on paper along with hand calculations to determine expected output. Add onto the algorithm from Problem Solving Challenge 1. Kathryn bought 750 shares of Microsoft Corporation (MSFT) stock at a price of $70.43 per share. She must pay her stock broker a 2% commission for the transaction. The algorithm should calculate and display the following: 1. The number of shares and stock symbol. 2....

  • Write an application that queries the user for the following information about a stock transaction and...

    Write an application that queries the user for the following information about a stock transaction and then displays the net gain or loss on the transaction. Number of shares bought and sold (this is one number not two) Purchase price per share Purchase commission as a double (for example, 2% commission would be 0.02) Sale price per share Sale commission as a double (for example, 2% commission would be 0.02) You must allow the user to enter the values. However...

  • Write an application that queries the user for the following information about a stock transaction and...

    Write an application that queries the user for the following information about a stock transaction and then displays the net gain or loss on the transaction. 1. Number of shares bought and sold (this is one number not two) 2. Purchase price per share 3. Purchase commission as a double (for example, 2% commission would be 0.02) 4. Sale price per share 5. Sale commission as a double (for example, 2% commission would be 0.02) You must allow the user...

  • Write a program based on the following flow chart and test the same for correct results? 2 points for each correct res...

    Write a program based on the following flow chart and test the same for correct results? 2 points for each correct results as follows Amount paid for the stock: 80000.00 Commission paid on the purchase: 2400.00 Amount the stock sold for 85500.00 Commission paid on the sale 2565.00 Profit (or loss if negative) 535.00 Start Display "Amount paid for stock: $", Constant Real Set totalPaid COMMISSION RATE= 0.03 Constant Integer NUM SHARES 2000 Constant Real PURCHASE PRICE 40.0 amountPaidForStock+ purchaseCommission...

  • walk me through all of these problems Selling Stocks When you sell your stocks, the sale...

    walk me through all of these problems Selling Stocks When you sell your stocks, the sale can result in either a profit or a loss. You profit when the sale amoun minus the sales commission is greater than the original purchase amount. Your sale results in a loss when the sale amount minus the sales commission is less than the original purchase amount NET SALE - AMOUNT OF SALE COMMISSION PROFIT - NET SALE TOTAL PAID LOSS - TOTAL PAID...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT