我正在Python中編寫一個公式,以幫助我在交易股票時輕鬆計算破解公式。其計算公式爲計算盈虧平衡點是:((股X價格)+提成)/(股)在Python中破解偶數公式
所以對於我的Python代碼,我寫道:
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
然而,當我運行它有時候並沒有得到正確的答案(通常在涉及小數時)。例如,當份額= 20,價格= 8.88和佣金= 10時,python給我答案爲8,但正確的答案是9.38。
誰能告訴我我哪裏出錯了,謝謝。
天才!使用「float」而不是「int」純粹的天才! – ng150716