I'm trying to write a simple code that figures out the tax and keeps a running total while you shop

Question:

I keep getting an error when I run this code that says it can only concantenate str (not int) to str. I’m extremely new to coding and well aware I’ve probably made a super obvious mistake but would like help pointing me in the right direction as to how I can resolve this for my little program.

T = 0
def amount(y, x = .0925):
    tax = y * x
    taxed = tax + float(y)
    taxed = round(taxed, 2)
    taxed = str(taxed)
    return taxed
user_input = ""
while user_input != "q":
    Cost = input("How Much Does It Cost? q to quit ")
    if Cost != "q":
        y = float(Cost)
        z = amount(y)
        z += T
        print("Your Total is " + z)
    if Cost == "q":
        break

Would greatly appreciate someone pointing out the (I’m sure) incredibly obvious thing I’m doing wrong here.

edit**
Thank you so much! after a quick edit to my code I was able to get this to run and function the way I wanted. I knew it had to be something obvious I didn’t have enough experience to see.

T = 0
def amount(y, x = .0925):
    tax = y * x
    taxed = tax + float(y)
    return round(taxed, 2)
user_input = ""
while user_input != "q":
    Cost = input("How Much Does It Cost? q to quit ")
    if Cost != "q":
        y = float(Cost)
        z = amount(y)
        T += z
        z = str(T)
        print("Your Total is " + z)
    if Cost == "q":
        break
Asked By: UltimaWraith

||

Answers:

Your function amount returns a string rather than a number, so you need to alter your function to e.g.

def amount(y, x = .0925):
    tax = y * x
    taxed = tax + float(y)
    return round(taxed, 2)

And then further down

   z = amount(y)
   z += T
   print("Your Total is " + z)

Otherwise you’re trying to add bananas to apples (string to integers).

Answered By: Jan
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.