Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is wrong with my bill calculator on google colab?

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

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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":
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading