Very new to programming here and this is a homework question.
The output I'm trying to generate looks as follows:
ENTER ITEMS (ENTER 0 TO END)
Cost of item: 152.50
Cost of item: 59.80
Cost of item: 0
Total: 212.3
Sales tax: 12.74
Total after tax: 225.04
Again? (y/n): n
Thanks, bye!
The code I've created so far is as follows:
I get that there is an error in line 13 but I don't understand where it is or how to fix it.
The error code is
The output I'm trying to generate looks as follows:
ENTER ITEMS (ENTER 0 TO END)
Cost of item: 152.50
Cost of item: 59.80
Cost of item: 0
Total: 212.3
Sales tax: 12.74
Total after tax: 225.04
Again? (y/n): n
Thanks, bye!
The code I've created so far is as follows:
#!/usr/bin/env python3 def get_cost(): total_cost = 0 while True: print("ENTER ITEMS (ENTER 0 TO END)") cost = str(input("Cost of item: ")) if cost == 0: print_cost(total_cost) break else: total_cost += cost def print_cost(total_cost): print("Total: " + str(total_cost)) print("Sales tax: " + str(total_cost * .06)) print("Total after tax: " + str(total_cost + (total_cost * .06))) print() def main(): print("Sales Tax Calculator") print() choice = "y" while choice.lower() == "y": get_cost() # see if the user wants to continue choice = input("Again? (y/n): ") print() print("Thanks, bye!") if __name__ == "__main__": main()
I get that there is an error in line 13 but I don't understand where it is or how to fix it.
The error code is
File "c:\Users\Student\Downloads\Project 4_401.py", line 35, in <module> main() File "c:\Users\Student\Downloads\Project 4_401.py", line 26, in main get_cost() File "c:\Users\Student\Downloads\Project 4_401.py", line 13, in get_cost total_cost += cost builtins.TypeError: unsupported operand type(s) for +=: 'int' and 'str'