#Initialization
count=0
name=0
#Input
while name!='-999':
count=count+1
name=input("Enter stock name OR -999 to Quit:")
shares=int(input("Enter number of shares:"))
pp=float(input("Enter purchase price:"))
sp=float(input("Enter selling price:"))
commission=float(input("Enter commission:"))
#Calculations
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)
#Output
print("Stock 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'))
===============================OUTPUT===================================================
Enter stock name OR -999 to Quit:Google
Enter number of shares:10000
Enter purchase price:39.99
Enter selling price:35.99
Enter commission:0.04
Enter stock name OR -999 to Quit:Amazon
Enter number of shares:10000
Enter purchase price:15.99
Enter selling price:33.99
Enter commission:0.04
Enter stock name OR -999 to Quit:-999
Enter number of shares:10000
Enter purchase price:14.99
Enter selling price:49.99
Enter commission:0.04
Stock Name: -999
Amount paid for the stock: $ 149,900.00
Commission paid on the purchase: $ 5,996.00
Amount the stock sold for: $ 499,900.00
Commission paid on the sale: $ 19,996.00
Profit (or loss if negative): $ 324,008.00
GoogleとAmazonの在庫を入力していますが、「-999」を実行すると印刷されませんwhileループから脱出する。代わりに、 "-999"はストック名であり、偽の番号を入力して印刷すると終了すると考えています。私は何が間違っているのか分かりません。ループが入力を印刷しないうちに、ループが中断しない
赤いニシンかもしれませんが、 'while name!=' - 999 ':' not 'while while name!= " - 999" '? – XtrmJosh
@XtrmJoshそれはまったく同じです... – Bharel
私は@Bharelを期待していますが、一番矛盾しています:) – XtrmJosh