Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

Students also viewed these Databases questions