Answer to Question #166323 in Python for Kassey Kasper

Question #166323

Create a python program using Loops (while or for loop) and if condition that will display 5 different kinds of fruits with price) and ask the user what to order( O- to take order)(N to terminate loop and display all the users order/s including the total price) . The program will request the user to input amount of money for the payment (do some validation) and lastly it will display the change if any.


1
Expert's answer
2021-02-24T03:25:29-0500
def Order():
    NetBill=0
    Cost_Orange = 1
    Cost_Apple  = 1.5
    Cost_Banana = 1
    Cost_Papaya = 2
    Cost_Melon  = 2.5
    print("Unit Cost of Orange = US $ %.2f"%Cost_Orange)
    print("Unit Cost of Apple  = US $ %.2f"%Cost_Apple)
    print("Unit Cost of Banana = US $ %.2f"%Cost_Banana)
    print("Unit Cost of Papaya = US $ %.2f"%Cost_Papaya)
    print("Unit Cost of Melon  = US $ %.2f"%Cost_Melon)


    print("")
    Qty_OR = float(input("Enter the Orange Qty. = "))
    Qty_AP = float(input("Enter the Apple  Qty. = "))
    Qty_BA = float(input("Enter the Banana Qty. = "))
    Qty_PA = float(input("Enter the Papaya Qty. = "))
    Qty_ML = float(input("Enter the Melon  Qty. = "))


    TotalCost_OR=0;
    TotalCost_AP=0
    TotalCost_BA=0
    TotalCost_PA=0
    TotalCost_ML=0
    print("\n\nBill")
    if(Qty_OR>0):
        TotalCost_OR = Qty_OR*Cost_Orange
        print("%.0f Orange(s) each at $ %.2f costs  = $ %.2f"%(Qty_OR,Cost_Orange,TotalCost_OR))
    if(Qty_AP>0):
        TotalCost_AP = Qty_AP*Cost_Apple
        print("%.0f Apple(s)  each at $ %.2f costs  = $ %.2f"%(Qty_AP,Cost_Apple,TotalCost_AP))
    if(Qty_BA>0):
        TotalCost_BA = Qty_BA*Cost_Banana
        print("%.0f Banana(s) each at $ %.2f costs  = $ %.2f"%(Qty_BA,Cost_Banana,TotalCost_BA))
    if(Qty_PA>0):
        TotalCost_PA = Qty_PA*Cost_Papaya
        print("%.0f Papaya(s) each at $ %.2f costs  = $ %.2f"%(Qty_PA,Cost_Papaya,TotalCost_PA))
    if(Qty_ML>0):
        TotalCost_ML = Qty_ML*Cost_Melon
        print("%.0f Melon(s)  each at $ %.2f costs  = $ %.2f"%(Qty_ML,Cost_Melon,TotalCost_ML))


    Total = TotalCost_OR+TotalCost_AP+TotalCost_BA+TotalCost_PA+TotalCost_ML
    Discount = 0.10*Total
    print("Total Bill                                 = %.2f"%Total)
    print("Discount (10 Percent)                      = %.2f"%Discount)
    Net = Total - Discount
    print("Total after discount                       = %.2f"%Net)
    Tax = 0
    NetBill = Net + Tax
    print("Total Bill Amount                          = %.2f"%NetBill)
    Amount = float(input("\nAmount Tendered           = US $ "))
    Balance = Amount - NetBill
    print("Balance                                    = %.2f"%Balance)
    return(NetBill)        




Flag=1
No_of_Orders=0
Val=0
while(Flag):
    Val = Val + Order()
    if(Val>0): No_of_Orders=No_of_Orders+1
    Or = input("\n\nPress O/o to continue or N/n to QUIT: ")
    if(Or == 'O' or Or=='o'): Flag=1
    else                    : Flag=0  


Python Output











Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS