Question: I am trying to create a program that will ask you to enter amount of money. The program will then output how much tax will

I am trying to create a program that will ask you to enter amount of money. The program will then output how much tax will be on the total amount and then the program will display the TOTAL cost with the amount AND the tax. If a user enters something like "$43.50" where there is a "$" sign and a ".", then the program should be able to read it and understand it is just 43.50. So, the user can input any number from 0-9, the "$" symbol, and a "." decimal.

If the user does not enter a correct input (any string that contains letters or symbols besides "$" and "."), then the program should automatically output "-1". After the program outputs the total cost, the program should ask the user again to enter an amount. The program will stop once the user enters "exit".

I have included my code below (this is the code I have so far so it's not completely finished), but it isn't giving me the right output.

def price_to_int(text): res = 0 valid = "$,.1234567890" for l in text: if l in valid: res = res * 10 else: print("-1") return res print("Determine Price with Tax.") print("Enter 'exit' at any time to quit.") word = input("Enter Amount ($X,XXX.XX): ") while word.lower() != "exit": d = price_to_int(word) tax = 0.06 print("Amount:",round(d,2)) print("Tax:",round(d*tax,2)) print("Price w/ Tax:",round(d+d*tax,2)) word = input("Enter Amount ($X,XXX.XX): ")

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!