user1693293
user1693293

Reputation: 9

Displaying tax total and total using purchase price? Python programming

print ("What is/was your original purchase price?")
x = input
valx=float(x)

print ("Amount of original purchase: ${}"
   .format(valx))
print ("State sales tax on original purchase: ${}"
   .format(valx*.04))
print ("County sales tax on original purchase: ${}"
   .format(valx*.02))
print ("Total sales tax (county and state): ${}"
   .format(valx*.06))
print ("Total of the sale (original purchase and total sales tax): ${}"
   .format(valx*.06))

this makes sense to me and I've used this method in the past, however it doesn't work now.

Output error: line 9, in <module>builtins.TypeError: float() argument must be a string or a number

basically my goal is to display the amount of the original purchase, the amount of the state sales tax(4%) on the original purchase, the amount of the county sales tax(2%) original purchase, the total sales tax (county tax plus state tax), and final the total of the sale (which is the sum of the amount of the original purchase plus the total sales tax).

Upvotes: 1

Views: 1543

Answers (4)

Dr. Jan-Philip Gehrcke
Dr. Jan-Philip Gehrcke

Reputation: 35796

For security reasons, you should use raw_input() instead of input(). The latter is the same as eval(raw_input(prompt)) and eval is not far from evil :)

Upvotes: 0

Makoto
Makoto

Reputation: 106470

The way to retrieve input from the command line would be this:

valx=float(input("What is/was your original purchase price?"))

input is a string, and you convert it to a float by wrapping that call. You then don't need the extra variable.

Upvotes: 0

John La Rooy
John La Rooy

Reputation: 304395

Presumably there are 6 lines above that you thought we didn't need to see. It makes talking about line 9 a bit useless though.

Surely you mean to call the input function

x = input()

Upvotes: 0

Aesthete
Aesthete

Reputation: 18848

You're assigning a function to the variable x

x = input
>> x
<built-in function input>

So you're not giving the float() function a string or number, but a function.

I think what you're trying to do is call the input() function. You can also integrate your message into it.

x = input ("What is/was your original purchase price?")

Or if you're using python 3 or greater, you'll need to convert the input from string to float (or integer, or whatever type you want.):

x = float(input("What is/was your original purchase price?"))

Upvotes: 3

Related Questions