I was writing a formula in python to help me easily calculate the break even formula when trading stocks. The formula is to calculate the break even point is: ((shares x price)+commission)/(shares)
So for my python code I wrote:
shares = int(input("How many shares did you purchase: "))
price = int(input("At what price did you buy: "))
commission = int(input("How much did you pay in commission: "))
break_even= ((shares*price)+commission)/(shares)
print break_even
However, when I run it I don't get the correct answer sometimes (usually when there is a decimal involved). For example, when shares = 20, price = 8.88 and commission = 10, python gives me the answer as 8, but the correct answer is 9.38.
Can anyone tell me where I went wrong, thanks.