Question: def calculate _ total ( ) : # Initialize variables total _ cost = 0 total _ tax = 0 item _ number = 1

def calculate_total(): # Initialize variables total_cost =0 total_tax =0 item_number =1 more_items ='y' taxable_items =[] # Loop to get item details while more_items.lower()=='y': print(f"
Item {item_number}") count = int(input(f"Enter count of item {item_number}: ")) unit_cost = float(input(f"Enter unit cost for item {item_number}: ")) is_taxable = input("Is this item taxable (y/n)?") cost = count * unit_cost # Calculate cost of item total_cost += cost # Add item cost to total cost # If item is taxable, add its cost to taxable_items list if is_taxable.lower()=='y': taxable_items.append(cost) more_items = input("More items (y/n)?") item_number +=1 # Increment item number tax_rate = float(input("
Enter sales tax rate (%): ")) # Get sales tax rate # Calculate tax for each taxable item and add to total tax for cost in taxable_items: tax = cost *(tax_rate /100) total_tax += tax total_cost_with_tax = total_cost + total_tax # Calculate total cost after tax # Print total cost before tax, total sales tax, and total cost after tax print(f"
Total cost (pre-tax): {total_cost:.2f}") print(f"Sales tax: {total_tax:.2f}") print(f"Total cost (with tax): {total_cost_with_tax:.2f}")calculate_total() # Call the function

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!