-2

My python bill calculator is not working in colab and I don't know how to fix it. I run it and it asks for the bill total so i type "123.45". Then it askes for what method i want and I type "Splitter" and it runs the tax part of the code.

bill_total = float(input("What is the bill total?  "))
method = str(input('''What method would you like to use?
Tax = Calculate the tax on your bill
Splitter = Calculate the distribution between multiple people.
'''))

if method == "Tax" or "tax" or "TAX":
  tax = float(input("What is the tax per dollar? (eg: 0.05)  "))
  result = bill_total*tax
  print(f"{message}{result} with tax.")


if method == "Splitter" or "SPLITTER" or "splitter":
  amount = float(input("What is the amount of people you are splitting with? (eg: 2)  "))
  result = bill_total/amount
  print(f"{message}{result} per person.")


if method != "Tax" and "tax" and "TAX" and "Splitter" and "SPLITTER" and "splitter":
  print("Error. Unknown method. Try again.")
  quit

1 Answers1

2

These if statements don't do what you're hoping:

if method == "Tax" or "tax" or "TAX":

You should write the conditions this way:

if (method == "Tax") or (method == "tax") or (method == "TAX"):

Or even better,

if method.lower() == "tax":
Jim Lewis
  • 43,505
  • 7
  • 82
  • 96