def load():
name=0
count=0
totalpr=0
name=input("Enter stock name OR -999 to Quit: ")
while name != '-999':
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
name=input("Enter stock name OR -999 to Quit: ")
def calc():
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)
totalpr=totalpr+profit_loss
def print():
print("\nStock 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'))
print("Total Profit is $", format(totalpr, '10,.2f'))
def main():
load()
calc()
print()
위의 함수를 호출하는 main() 함수를 작성하고 싶습니다.출력이 비어 있습니다.
그러나 프로그램을 실행할 때 출력은 공백입니다. 아무 것도 없습니다. 문제를 설명하기 위해 오류가 없습니다.
내가 뭘 잘못하고 있니?
내장 된'print()'함수를 오버라이드하고 있습니다 ... 다른 이름을 사용하십시오 – qxz
변경했습니다. 아직 아무 일도 일어나지 않았다. –
또한 범위 문제가 있습니다. 각 함수에 정의 된 모든 변수는 다른 변수의 범위를 벗어납니다. –