OnlineGDB: LINK PythonOnline: LINK An online store needs a…
OnlineGDB: LINK PythonOnline: LINK An online store needs a program to calculate the total cost of items in a shopping cart, including tax. You need to write a function that handles potential errors when processing the cart data. Write a function calculate_total(items, tax_rate) that: Takes a list of item prices (as strings) and a tax_rate (as a string representing a percentage, e.g., “8.5”) Converts all prices to floats, calculates the subtotal, applies the tax rate, and returns the final total Handles the following exceptions appropriately: ValueError: Print “Error: Invalid price or tax rate format. Please enter valid numbers.” and return 0 TypeError: Print “Error: Items must be provided as a list.” and return 0 ZeroDivisionError: Print “Error: Cannot perform calculation.” and return 0 Uses a finally block to print “Calculation attempt completed.” Formula: total = subtotal + (subtotal * tax_rate / 100) Example usage # Test 1: Valid inputtotal = calculate_total(, “8.5”)print(f”Total: ${total:.2f}”)# Output:# Calculation attempt completed.# Total: $55.87# Test 2: Invalid price formattotal = calculate_total(, “8.5”)# Output:# Error: Invalid price or tax rate format. Please enter valid numbers.# Calculation attempt completed.# Test 3: Invalid tax ratetotal = calculate_total(, “eight”)# Output:# Error: Invalid price or tax rate format. Please enter valid numbers.# Calculation attempt completed.# Test 4: Wrong data type (not a list)total = calculate_total(“10.99”, “8.5”)# Output:# Error: Items must be provided as a list.# Calculation attempt completed.