Error string to float
<p>This is my code. I am doing a beginer execise. When I run the program </p>

<p>I can put the values, but when I go out of the loop the following error message appears:</p>

<pre><code> a + = float (input ("Enter the product cost"))
</code></pre>

<p>ValueError: could not convert string to float:</p>

<p>Can someone help me?</p>

<p>Here it goes:</p>

<pre><code>e = 0.25
f = 0.18
a = 0.0

while True:
    a += float(input("Enter the product cost:  "))
    if a == "":        
        break

b = a*e
c = a*f
d = a+b+c

print ("tax: " + b)
print ("tips: " + c)
print ( "Total: " + d)
</code></pre>

<p>There are a couple of issues:</p>

<ol>
<li>the check for a being an empty string <code>("")</code> comes <em>after</em> the attempt to add it to the <code>float</code> value <code>a</code>. You should handle this with an exception to make sure that the input is numerical.</li>
<li>If someone doesn't enter an empty or invalid string, ever, then you get stuck in an infinite loop and nothing prints. That's because the indentation of your <code>b, c, d</code> calculations and the <code>prints</code> is outside of the scope of the <code>while</code> loop.</li>
</ol>

<p>This should do what you want:</p>

<pre><code>e = 0.25
f = 0.18
a = 0.0

while True:
    try:
        input_number = float(input("Enter the product cost:  "))
    except ValueError:
        print ("Input is not a valid number")
        break
    a += input_number        
    b = a*e
    c = a*f
    d = a+b+c

    print ("tax: ", b)
    print ("tips: ", c)
    print ( "Total: ", d)
</code></pre>

python python-3.x