0

relatively new to programming in python, thank you for all the fast help that was provided on my last question I had on another python project. Anyways, Ive written a new program for a project in python that produces a bill for a catering venue. This is my code below, everything runs fine, and I get the intended results required for the project, The two problems I am experience are, 1. I need the cost of the desert to not print---> 3.0 but ---> $3.00, essentially, how can I print dollar signs, and round e.x 3.0 --> 3.00, or 45.0--> 45.00..and with dollar signs before prices. Sorry if something like this has been asked..

import math

#  constants

Cost_Per_Desert = 3.00
Tax_Rate = .075
Gratuity_Tips = .15
Adult_Meal_Cost = 12.75
Child_Meal_Cost = .60*12.75
Room_Fee = 450.00
Less_Deposit = 250.00


   def main():

   #         Input Section


    Name = input("\n\n Customer:\t\t\t ")
    Number_Of_Adults = int(input(" Number of Adults:\t\t "))
    Number_Of_Children = int(input(" Number of Children:\t\t "))
    Number_Of_Deserts = int(input(" Number of Deserts:\t\t "))



   print("\n\nCost Of Meal Per Adult:\t\t" , Adult_Meal_Cost)
   print("Cost of Meal Per Child:\t\t" , round(Child_Meal_Cost,2))
   print("Cost Per Desert:\t\t" , round(Cost_Per_Desert,2))


   #        Processing/Calculations

    Total_Adult_Meal_Cost = Adult_Meal_Cost* Number_Of_Adults

    Total_Child_Meal_Cost = Child_Meal_Cost* Number_Of_Children

   Total_Desert_Cost = Cost_Per_Desert* Number_Of_Deserts

   Total_Food_Cost = Total_Adult_Meal_Cost + Total_Child_Meal_Cost       +         Total_Desert_Cost

Total_Taxes = Total_Food_Cost * Tax_Rate

Tips = Total_Food_Cost * Gratuity_Tips    

Total_Bill = Total_Food_Cost + Total_Taxes + Tips + Room_Fee


#       Output Section

print("\n\n Total Cost for Adult Meals: \t", Total_Adult_Meal_Cost)

print(" Total Cost for Childs Meals: \t", Total_Child_Meal_Cost)

print(" Total Cost for Desert: \t", Total_Desert_Cost)

print(" Total Food Cost: \t\t", Total_Food_Cost)

print("\n\n Plus 7.5% Taxes: \t\t", round(Total_Taxes,2))

print(" Plus 15.0% Tips: \t\t", round(Tips,2))

print(" Plus Room Fee: \t\t", Room_Fee)


print("\n\n Total Bill: \t\t\t", round(Total_Bill,2))

print(" Less Deposit: \t\t\t", Less_Deposit)

print("\n\nBalance Due: \t\t\t", round(Total_Bill - Less_Deposit,2))

print("\n\n\n\n\t\t Thank You For Using Passaic County Catering Services. ")


main()
input("\n\n\n\n\nPress Enter to Continue")
Bhuwan Prasad Upadhyay
  • 2,916
  • 1
  • 29
  • 33
red
  • 17
  • 2
  • 8

2 Answers2

1

Let's say cost of desert is $3.00

cost = 3
print("${0:.2f}".format(cost))

Output:

$3.00
YBathia
  • 894
  • 1
  • 8
  • 18
0
  1. When you need to add a $ sign you just simply put a $ sign in your string.
  2. If you would like to fix the decimal number places you just need basic string formatting, like: print('pi is %.2f' % 3.14159) and the output would be pi is 3.14

You might wanna like to read: https://docs.python.org/2.7/library/string.html#formatspec

Fingalzzz
  • 109
  • 14