【发布时间】:2022-06-20 13:14:56
【问题描述】:
(这是我发现@gooney 没有回答的问题)
今年夏天刚开始我的第一个计算机科学课程,需要一些帮助。
我们的任务是制作一个股票交易程序(无关紧要),我在两件事上遇到了麻烦。每当我从文件资源管理器中打开 .py 文件时,它会在第 6 次输入后崩溃。每当我直接从 cmd(python“文件名”)或在 IDLE 中运行它时,它都可以正常工作,所以我很困惑。
任何帮助将不胜感激。这是我的代码以及它在 CMD 中的样子。 [代码][2]
# This program will be used to determine
# Calculations for a stock transaction
# The inputs
Shares_Bought = int(input('Enter shares purchased: '))
SharePrice_B = float(input('Enter purchase price of shares: '))
B_Commission = float(input('Enter broker buy commission: '))
Shares_Sold = int(input('Enter shares sold: '))
SharePrice_S = float(input('Enter sell price of shares: '))
S_Commission = float(input('Enter broker sell comission: '))
#CONSTANTS?
TOTAL_PURCHASE = Shares_Bought * SharePrice_B
TOTAL_SALE = Shares_Sold * SharePrice_S
TOTAL_SALES_COMMISSION = (Shares_Bought * SharePrice_B) * (B_Commission / 100) + (Shares_Sold * SharePrice_S) * (S_Commission / 100)
# The outputs
print('Alex Partida Stock Transaction App')
print(f'Joe Paid: ${Shares_Bought * SharePrice_B:,.2f}')
print(f'Purchase Commission: ${(Shares_Bought * SharePrice_B) * (B_Commission / 100):,.2f}') # Need to make this shorter/split into more lines
print(f'Joe sold at: ${Shares_Sold * SharePrice_S:,.2f}')
print(f'Sales Commission: ${(Shares_Sold * SharePrice_S) * (S_Commission / 100):,.2f}')
print(f"Joe's Profit: ${(TOTAL_SALE - TOTAL_PURCHASE) - TOTAL_SALES_COMMISSION:,.2f}")
【问题讨论】:
标签: python