Python Code not Working in Certain Versions
<p>So for my school, I have to make this script that calculates the tip and tax of a meal. I'm ahead of everyone in my class, so no others have had this issue. </p>

<p>The code works fine in the Python3 IDLE on my PC, it also works fine at <a href="https://repl.it/languages/python3" rel="nofollow">repl.it</a>. Oddly enough, at my school's IDLE, which is private, and <a href="http://pythonfiddle.com/" rel="nofollow">Python Fiddle, which is pretty much the same</a> the tip and the tax do not properly calculate. </p>

<p>Also, there are some other bugs, such as displaying extra digits or not enough digits. I tried my hardest to fix this with string slicing but it didn't work. The only other way I know how to do it is with <strong>if</strong> statements which aren't allowed.</p>

<p>Any help would be appreciated, thanks in advance.</p>

<p>Code:</p>

<pre><code>#Name
#9/20/16
#This program calculates the total cost of a meal.

def main():
    #INPUT
    meal = float(30.96)
    am = int(input("How many meals would you like? "))
    tx = int(input("What is the tax %? "))
    tp = int(input("How much % do you want to tip?" ))
#CALCULATIONS   
    subT = am*meal
    tax1 = tx/100
    tax = tax1*subT
    subTotalWithTax = subT + tax
    tip1 = tp/100
    tip = tip1*subTotalWithTax
    total = subTotalWithTax + tip
    clTip = str(tip)[0: 4]
    clTax = str(tax)[0: 4]
    clTotal = str(total)[0: 6]
    clSubT = str(subT)[0: 6]
#OUTPUT
    print("-----------------------------------------------")
    print("Items: ")
    print(str(am) + " Overloaded Potato Skins ------------- $7.99")
    print(str(am) + " Grilled Top Sirloin 12oz ------------ $16.49")
    print(str(am) + " Sweet Tea --------------------------- $1.99")
    print(str(am) + " Southern Pecan Pie ------------------ $3.99")
    print("------------------------------------------------")
    print("Totals: ")
    print("Subtotal: ----------------------------- $" + str(clSubT))
    print("Tax: ---------------------------------- $" + str(clTax))
    print("Tip: ---------------------------------- $" + str(clTip))
    print("Total --------------------------------- $" + str(clTotal))
    print("------------------------------------------------")
main()
</code></pre>

<p>The fact that you get $0 as answer may show that python (2, likely) still represents numbers as integers. Try explicitly casting to floats.
Such as:</p>

<pre><code>tip1 = tp/100.0  # instead of 100
</code></pre>

<p>or</p>

<pre><code>tx = float(input("What is the tax %? "))
</code></pre>

<p>Also the clipping for displaying is a bit messy, try</p>

<pre><code>print("Total --------------------------------- ${}".format(total))
</code></pre>

<p>The <code>.format()</code> is the trick you're looking for. There are ways to show only two decimals, check around SO or <a href="https://pyformat.info/" rel="nofollow">https://pyformat.info/</a> --but do try
<code>"{:.2f}".format(total)</code> :-)</p>

<hr>

<p><strong>Edit</strong>
Alternatively, without <code>format</code>: <code>print("%.2f" % total)</code></p>

<p>And now, for a completely convoluted way to print the price (that is, if formatting is not allowed but string manipulation is):</p>

<pre><code>totalDollar, totalCent = str(total).split('.')
totalCent += "00"
print("Total --------------------------------- $" + totalDollar + "." + totalCent[:2])
</code></pre>

python python-2.7 python-3.x calculator