The formula for "Two-for" price is 20% off the total price of two items. Prompt the user for each of the values and calculate the result
<p>The following is what the output should look like:</p>

<p>Enter price 1: 10.0</p>

<p>Enter price 2: 20.0</p>

<p>The 'two-for' price is $24.0</p>

<p>The code I entered is:</p>

<pre><code>price_one = float(input('Enter price 1: '))

print(price_one)

price_two = float(input('Enter price 2: '))

print(price_two)

two_for_price = (price_one + price_two)-((price_one + price_two)*(20/100))

print("The 'two-for' price is $",two_for_price) 
</code></pre>

<p>(The inputs are 10.0 and 20.0 respectively.)</p>

<p>But the output I am getting is:</p>

<pre><code>Enter price 1: 10.0

Enter price 2: 20.0

The 'two-for' price is $ 24.0
</code></pre>

<p>In the last line I need:</p>

<pre><code>The 'two-for' price is $24.0
</code></pre>

<p>Please help me out!!</p>

<p>Your underlying problem is that the <code>print</code> function behavior, given a list of items, is to print each item, separated by a space.  This is often convenient for quick-and-dirty print-outs, but you want something more refined.</p>

<p>What you need to do is create a string with the proper spacing and then print that string out.</p>

<p>So you could do this:</p>

<pre><code>print("The 'two-for' price is $" + str(two_for_price) + ".")
</code></pre>

<p>The problems are (a) that's kind of clumsy and unreadable and (b) it does not format properly, it's "$2.6" instead of "$2.60".</p>

<p>You can use either of two formatting mechanisms offered by Python, either explicit, like this:</p>

<pre><code>print("The 'two-for' price is ${0}".format(two_for_price))
</code></pre>

<p>or implicit, like this</p>

<pre><code>print("The 'two-for' price is $%f" % two_for_price)
</code></pre>

<p>Both of them look a little better, but the formatting errors are the same and worse ("$2.600000"!) respectively.  Fortunately, both offer nice customizable formatting:</p>

<pre><code>print("The 'two-for' price is ${0:.2f}".format(two_for_price))
</code></pre>

<p>and</p>

<pre><code>print("The 'two-for' price is $%0.2f" % two_for_price)
</code></pre>

<p>Both of which look reasonably clean and display perfectly.</p>

python