Editor

Apply Sales Tax

Intermediate · Write the code · from NumPy Operations: Element-wise Math, Aggregations, and ufuncs

From the lesson: NumPy Operations: Element-wise Math, Aggregations, and ufuncs

You know how to create NumPy arrays. Now it's time to actually do things with them. The real power of NumPy is that you can perform math on entire arrays at once - no loops required.

Read the lesson

Given an array of prices [19.99, 35.50, 8.99, 124.00, 56.75], calculate the total cost after adding 7.5% sales tax. Print the result rounded to 2 decimal places using np.round().

import numpy as np
prices = np.array([19.99, 35.50, 8.99, 124.00, 56.75])
# Calculate total with 7.5% tax and print rounded

More NumPy Operations exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz