python - Why do I get TypeError: can't multiply sequence by non-int of type 'float'? -


I'm typing to get sales amount (by input) to multiply by defined sales tax (0.08) And then prints the total amount (sales tax bar sales amount) after that.

I go into this error. Anyone knows what can be wrong or some suggestion?

  salesAmount = raw_input (["insert sales volume here \ n"]) [[Enter the combined sales amount here]] 20.9 9 >> gt; & Gt; SalesTax = 0.08 & gt; & Gt; & Gt; TotalAmount = salesAmount * SalesTax Traceback (Most Recent Call End): File "& lt; pyshell # 57" gt; Line 1, & lt; Module & gt; Total Amount = SalesAmount * SalesTax TypeEight: Can not multiply the sequence by the non-int type of 'float'  

raw_input returns a string (sequence of characters). In Python, multiplication of a string and a float has no defined meaning (whereas string multiplication and an integer mean: "ab" * 3 is "ababab" ; lot "L" * 3.14 , please do not answer "LLL |" . You need to parse the string in a numeric value.

You can try:

  salesAmount = float (raw_input ("enter the sales amount here \ n"))  

Comments