python programming Stock Transaction Program Last month Joe

python programming: Stock Transaction Program Last month Joe purchased some stock from Schmoe Inc. Write a program that allows the user to input the following as many times as he/she wants until the user is done (example it can be 5times): 1.The name of the Stock 2.Number of shares Joe bought 3.Stock purchase price 4.Stock selling price 5.Broker commissionDisplays t he following paid for the stock(s) that Joe had transacted (if Joe entered 5 sets of stocks transactions then output 5 sets of stocks). 1.The Name of the Stock 2.The amount of money Joe paid for the stock (number of shares bought * purchase price) 3.The amount of commission Joe paid his broker when he bought the stock. (Amount he paid for stocks * commission in percent) 4.The amount that Jim sold the stock for. (number of shares * selling price) 5.The amount of commission Joe paid his broker when he sold the stock. (Amount he sold sh ares * commission in percent) 6.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 Joe lost money. Profit/loss =(amount sold stocks for-commission) –(amount paid for stocks+commission)

Solution

#Stock Transaction program in Python
# Store number of input from the user
num = input (\'Enter How many times you want to execute: \')
stock=[[]] # 2D to store the value in array

# Append empty lists in first indexes.
for x in range(0, num):
stock.append([])
stockName = raw_input (\'Enter the stock name: \')
numOfStock= raw_input (\'Enter the number of stock: \')
stockPurPrice= raw_input (\'Enter the stock purchase price: \')
stockSellPrice= raw_input (\'Enter the stock selling price: \')
brokerCom= raw_input (\'Enter the broker commission: \')
stock[x].append(stockName)
stock[x].append(numOfStock)
stock[x].append(stockPurPrice)
stock[x].append(stockSellPrice)
stock[x].append(brokerCom)

# Loop over rows for each stock.
print(\'stock size is \',len(stock))
for i in range(len(stock)-1):
stockName=stock[i][0]
numOfStock=stock[i][1]
stockPurPrice=stock[i][2]
stockSellPrice=stock[i][3]
brokerCom=stock[i][4]
amountPaidForStockBuying=float(numOfStock)*float(stockPurPrice)
CommForBuying=float(amountPaidForStockBuying)*float(brokerCom)/100
amountGotForStockSelling=float(numOfStock)*float(stockSellPrice)
CommForSelling=float(amountGotForStockSelling)*float(brokerCom)/100
Cost=(amountGotForStockSelling-CommForSelling)-(amountPaidForStockBuying+CommForBuying)
print(\'Stock Name: {0}\'.format(stockName))
print(\'The amount of money Joe paid for the stock: {0}\'.format(amountPaidForStockBuying))
print(\'The amount of commission Joe paid his broker when he bought the stock: {0}\'.format(CommForBuying))
print(\'The amount that Jim sold the stock for: {0}\'.format(amountGotForStockSelling))
print(\'The amount of commission Joe paid his broker when he sold the stock: {0}\'.format(CommForSelling))
print(\'Profit/Loss: {0}\'.format(Cost))
if Cost<0:
print(\'You are in loss!\')
else:
print(\'You are in profit!\')

/*************output************/

Enter How many times you want to execute: 2
Enter the stock name: AAA
Enter the number of stock: 100   
Enter the stock purchase price: 9
Enter the stock selling price: 10
Enter the broker commission: 1   
Enter the stock name: BBB
Enter the number of stock: 100   
Enter the stock purchase price: 10   
Enter the stock selling price: 9   
Enter the broker commission: 1   
Stock Name: AAA   
The amount of money Joe paid for the stock: 900.0
The amount of commission Joe paid his broker when he bought the stock: 9.0
The amount that Jim sold the stock for: 1000.0   
The amount of commission Joe paid his broker when he sold the stock: 10.0   
Profit/Loss: 81.0
You are in profit!   
Stock Name: BBB
The amount of money Joe paid for the stock: 1000.0   
The amount of commission Joe paid his broker when he bought the stock: 10.0   
The amount that Jim sold the stock for: 900.0
The amount of commission Joe paid his broker when he sold the stock: 9.0
Profit/Loss: -119.0
You are in loss!

/**********************output ends********************//

Note: please feel free to ask any doubts. God bless you!!!

python programming: Stock Transaction Program Last month Joe purchased some stock from Schmoe Inc. Write a program that allows the user to input the following a
python programming: Stock Transaction Program Last month Joe purchased some stock from Schmoe Inc. Write a program that allows the user to input the following a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site