내 학교의 경우 식사의 팁과 세금을 계산하는 스크립트를 만들어야합니다. 나는 내 반의 모든 사람들보다 앞서 있기 때문에 다른 사람들은이 문제를 가지고 있지 않다.Python 코드가 특정 버전에서 작동하지 않습니다.
코드는 내 PC의 Python3 IDLE에서 올바르게 작동하며, repl.it에서도 정상적으로 작동합니다. 기발한만큼, 내 학교의 IDLE은 개인이며 Python Fiddle, which is pretty much the same 팁과 세금이 제대로 계산되지 않습니다.
또한 추가 숫자 표시 또는 숫자가 충분하지 않은 것과 같은 몇 가지 버그가 있습니다. 나는 이것을 문자열 조각으로 해결하기 위해 가장 열심히 노력했지만 효과가 없었다. 내가 그것을하는 방법을 알고있는 유일한 다른 방법은 허용되지 않는 문장 인 경우 입니다.
도움을 주시면 감사하겠습니다. 미리 감사드립니다.
코드 :
#Name
#9/20/16
#This program calculates the total cost of a meal.
def main():
#INPUT
meal = float(30.96)
am = int(input("How many meals would you like? "))
tx = int(input("What is the tax %? "))
tp = int(input("How much % do you want to tip?"))
#CALCULATIONS
subT = am*meal
tax1 = tx/100
tax = tax1*subT
subTotalWithTax = subT + tax
tip1 = tp/100
tip = tip1*subTotalWithTax
total = subTotalWithTax + tip
clTip = str(tip)[0: 4]
clTax = str(tax)[0: 4]
clTotal = str(total)[0: 6]
clSubT = str(subT)[0: 6]
#OUTPUT
print("-----------------------------------------------")
print("Items: ")
print(str(am) + " Overloaded Potato Skins ------------- $7.99")
print(str(am) + " Grilled Top Sirloin 12oz ------------ $16.49")
print(str(am) + " Sweet Tea --------------------------- $1.99")
print(str(am) + " Southern Pecan Pie ------------------ $3.99")
print("------------------------------------------------")
print("Totals: ")
print("Subtotal: ----------------------------- $" + str(clSubT))
print("Tax: ---------------------------------- $" + str(clTax))
print("Tip: ---------------------------------- $" + str(clTip))
print("Total --------------------------------- $" + str(clTotal))
print("------------------------------------------------")
main()
학교에서 파이썬 3을 사용하고 있는지 확인하십시오. –
[이 답변] (http://stackoverflow.com/questions/1535596/what-is-the-reason-for-having-in-python)을 확인하십시오. 그것은 파이썬 2와 3의 차이 일 수 있습니다. –
파이썬 피들은 파이썬 2를 사용합니다. 학교의 IDLE은 파이썬 2이기도합니다.'/'연산자는 파이썬 3와 파이썬 2에서 다르게 동작합니다. – edwinksl