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>You're trying to convert a float to a string by doing <code>if a == ""</code>. Try the following:</p>

<pre><code>while True:
    a_input = input("Enter the product cost:  ")

    if a_input == "":  
        break

    try:
        a += float(a_input)
    except ValueError:
        break
</code></pre>

<p>This checks the input first, then converts to float. It saves the string to <code>a_input</code> and then checks, before incrementing <code>a</code>. It also does a <code>try-except</code> block to break the loop if conversion was unsuccessful. You should also want to place your calculations <strong>inside</strong> your loop.</p>

python python-3.x