Question: def calculate _ total ( ) : # Initialize variables total _ cost = 0 total _ tax = 0 item _ number = 1
def calculatetotal: # Initialize variables totalcost totaltax itemnumber moreitems y taxableitems # Loop to get item details while moreitems.lowery: printf
Item itemnumber count intinputfEnter count of item itemnumber: unitcost floatinputfEnter unit cost for item itemnumber: istaxable inputIs this item taxable yn cost count unitcost # Calculate cost of item totalcost cost # Add item cost to total cost # If item is taxable, add its cost to taxableitems list if istaxable.lowery: taxableitems.appendcost moreitems inputMore items yn itemnumber # Increment item number taxrate floatinput
Enter sales tax rate : # Get sales tax rate # Calculate tax for each taxable item and add to total tax for cost in taxableitems: tax cost taxrate totaltax tax totalcostwithtax totalcost totaltax # Calculate total cost after tax # Print total cost before tax, total sales tax, and total cost after tax printf
Total cost pretax: totalcost:f printfSales tax: totaltax:f printfTotal cost with tax: totalcostwithtax:fcalculatetotal # Call the function
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
