Featured resource
2026 Tech Forecast
2026 Tech Forecast

1,500+ tech insiders, business leaders, and Pluralsight Authors share their predictions on what’s shifting fastest and how to stay ahead.

Download the forecast
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Labs

Sales Tax Calculator in Python

Build a reusable Python sales tax calculator that starts with shell-style tax math and turns it into a saved script. Along the way, you will implement core math helpers, readable printed output, basic text input parsing, and a simple main entry point that can run in several modes.

Lab platform
Lab Info
Level
Beginner
Last updated
Jun 11, 2026
Duration
30m

Contact sales

By clicking submit, you agree to our Privacy Policy and Terms of Use, and consent to receive marketing emails from Pluralsight.
Table of Contents
  1. Challenge

    Step 1: Explore the Project and the Learning Path

    This lab turns a few lines of Python shell math into a small, reusable sales tax calculator program. The shell is great for quick experiments because it echoes values automatically. Scripts are what you keep, rerun, and share.

    To stay organized, this project splits responsibilities across a few files:

    • app/calculator.py — defaults and tax math
    • app/formatting.py — currency and summary output
    • app/io_helpers.py — input parsing and prompts
    • app/workflows.py — demo workflow
    • tax.py — script entry point

    The starter code includes tests for each task. Work through the tasks in order and run the check when you finish one. > If you get stuck, you can refer to the provided solution code for each task, available in the solution folder. info> This lab experience was developed by the Pluralsight team using an internally developed AI tool. All sections were verified by human experts for accuracy prior to publications. However, content may still contain errors or inaccuracies, and we recommend independent verification.

    To report a problem or provide feedback, click here. Feedback may be used to improve accuracy in accordance with our Privacy Policy.

  2. Challenge

    Step 2: Recreate the Shell Math in Reusable Calculator Functions

    This step builds the mathematical core in app/calculator.py. In the shell, one expression like amount + amount * tax is enough. In a script, it helps to name the pieces: defaults at the module level, a helper for tax only, and a helper for the full total. That separation makes the code easier to test and reuse. A common starting point is amount = 10 and tax = 0.06. In a script, those values belong in one clear place so the rest of the code can reuse them. Python often uses uppercase names such as DEFAULT_AMOUNT to signal stable default values. Next, pull the tax calculation into its own helper. The expression amount * tax becomes a function that returns only the tax portion, not the full total. The full formula is total = amount + amount * tax. Instead of repeating the multiplication, call calculate_tax() from calculate_total() so each function has one clear job.

  3. Challenge

    Step 3: Turn Raw Numbers Into Readable Script Output

    The shell shows a value when you type a variable name, but a saved script does not display anything unless you print it. This step adds formatting helpers and connects them to the script. Raw floats like 10.6 are not ideal for users. An f-string with a .2f format specifier can turn that into currency text such as $10.60. A single formatted number is not enough for a useful script. Build a multi-line summary that explains the amount, tax rate, and total, then return that string so other parts of the app can print or test it. Now connect the default calculator values to visible output. Build the summary first, then pass it to output_func so the script produces console output when it runs.

  4. Challenge

    Step 4: Accept New Values Through Text Input

    Changing values still means editing code unless the program can read input. User input arrives as text, so you need parsing and validation before the calculator can use the values. Start with the purchase amount. Strip whitespace, convert with float(), and reject invalid or negative values with ValueError. Tax rates are trickier because users may enter 0.06, 7, or 7%. Normalize those forms into one decimal rate the calculator can use, such as 0.07. With the parsers in place, wire up a small interactive workflow: prompt for both values, parse them, build the summary, and print the result.

  5. Challenge

    Step 5: Finish Reusable Workflows and the Script Entry Point

    The final step adds application flow. A demo workflow can show both example calculations in sequence, and main() gives the script one clear entry point. Start with one default calculation and then a rerun with new values. Package both examples into one reusable demo function instead of editing variables each time. Finish by routing execution through main(). The if __name__ == '__main__': guard keeps imports safe, while main() decides whether to run the default, demo, or prompt workflow. Run python tax.py to see the finished calculator. You now have reusable math helpers, readable output, input parsing, and a clean script entry point.

About the author

Pluralsight’s AI authoring technology is designed to accelerate the creation of hands-on, technical learning experiences. Serving as a first-pass content generator, it produces structured lab drafts aligned to learning objectives defined by Pluralsight’s Curriculum team. Each lab is then enhanced by our Content team, who configure the environments, refine instructions, and conduct rigorous technical and quality reviews. The result is a collaboration between artificial intelligence and human expertise, where AI supports scale and efficiency, and Pluralsight experts ensure accuracy, relevance, and instructional quality, helping learners build practical skills with confidence.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight