Trying to make my code shorter just a few points away from #1.
I tried shrinking it but its just too complicated.
Taxers = int(input("Will you be eating in 1 For Yes 2 For No:"))
TotalCostA = TotalCostB * 0.05
Tax = TotalCostA
TotalCostF = "{:.2f}".format(Tax)
TotalCostT = Tax + TotalCostB
if Taxers == 2:
print("Tax = 0")
print("Your total pizza cost it", TotalCostB, "kd")
else:
print("Tax = ", TotalCostF)
print("Your total pizza cost it", TotalCostT, "kd")
>Solution :
You can get rid of the extra variables and use f-strings for a slightly more fluent experience:
Taxers = int(input("Will you be eating in 1 For Yes 2 For No:"))
TotalCostA = TotalCostB * 0.05
TotalCostT = TotalCostA + TotalCostB
if Taxers == 2:
print("Tax = 0")
print(f"Your total pizza cost it {TotalCostB} kd")
else:
print(f"Tax = {TotalCostA:.2f}")
print(f"Your total pizza cost it {TotalCostT} kd")
Shortening it even further will reduce code readability. On that note, I strongly recommend you to follow the Python naming conventions and improve the variable names to something more descriptive, e.g. cost_with_tax.