미국 텍스트북 보면서 공부하고 있는 사람인데요 def 문을 공부하다가 궁금한게 있어서요!
print ("Sales Tax Calculator")
def calculations (total):
"""
Calculates sales tax
"""
rate = 6
return ((rate/100) * total)
def getTotal (total, salesTax):
return (total + salesTax)
def getItems ():
print ()
print ("ENTER ITEMS (ENTER 0 TO END)")
print ()
total = 0
while True:
cost = float (input ("Cost of item: "))
if cost == 0:
break
total += cost
total = round (total, 2)
salesTax = round(calculations (total),2)
totalwithTax = round (getTotal (total, salesTax), 2)
print ("Total:\t", total)
print ("Sales Tax: ", salesTax)
print ("Total after tax: ", totalwithTax)
def main ():
choice = "y"
while choice.lower() == "y":
getItems ()
print()
choice = input ("Again? (y/n) :")
print ()
print ("Thanks, bye!")
if __name__ == "__main__":
main()
혹시 calculations 모듈하고 getTotal 모듈을 합칠 수 있는 방법이 없을까요?
나름 합쳐본다고 했는데, syntax 에러가 떠요ㅠㅠ
print ("Sales Tax Calculator")
def calculations (total, salesTax, totalwithTax):
"""
Calculates sales tax
"""
rate = 6
salesTax = (rate/100) * total
totalwithTax = total + salesTax
return (total, salesTax, totalwithTax)
def getItems ():
print ()
print ("ENTER ITEMS (ENTER 0 TO END)")
print ()
total = 0
while True:
cost = float (input ("Cost of item: "))
if cost == 0:
break
total += cost
total = round (total, 2)
salesTax = round(salesTax,2)
totalwithTax = round (totalwithTax, 2)
print ("Total:\t", total)
print ("Sales Tax: ", salesTax)
print ("Total after tax: ", totalwithTax)
def main ():
choice = "y"
while choice.lower() == "y":
getItems ()
print()
choice = input ("Again? (y/n) :")
print ()
print ("Thanks, bye!")
if __name__ == "__main__":
main()
문제는 볼드 표시한 부분 같은데 어떻게 하면 오류 없이 제대로 표현할 수 있을까요?
저도 코딩이 처음이고 주변에 할 수 있는 사람이 없어서 한 번 여쭤봅니다ㅠㅠ
아래는 제가 생각하고 있는 결과값이에요!
Sales Tax Calculator
ENTER ITEMS (ENTER 0 TO END)
Cost of item: 52.31
Cost of item: 20
Cost of item: 18.2
Cost of item: 0
Total: 90.51
Sales Tax: 5.43
Total after tax: 95.94
Again? (y/n) :
python global