This Python code is an **Inventory Estimator With Error Tracker**...

September 3, 2025 at 02:12 PM

# # Mark Lewis # 09.02.2025 # Inventory Estimator With Error Tracker # # Get the starting numbers of paperbacks and hardbacks. books = int(input('What is the current number of books? ')) while books < 0 or books > 30: print("Number of books must be between 0 and 30.") books = int(input("Enter the number of books: ")) dvds = int(input('What is the current number of DVDs? ')) while dvds < 0 or dvds > 15: print("Number of DVDs must be between 0 and 15.") dvds = int(input("Enter the number of DVDs: ")) games = int(input('What is the current number of games? ')) while games < 0 or games > 10: print("Number of games must be between 0 and 10.") games = int(input("Enter the number of games: ")) print() # Calculate totals cost_before_tax = books * 2.25 + dvds * 4.35 + games * 5.00 sales_tax = cost_before_tax * 0.065 cost_after_tax = cost_before_tax + sales_tax # Print results print(f"Cost before tax: ${cost_before_tax:.2f}") print(f"Sales tax: ${sales_tax:.2f}") print(f"Cost after tax: ${cost_after_tax:.2f}")

This Python code is an Inventory Estimator With Error Tracker that calculates the total cost (before and after tax) for items in stock, considering books, DVDs, and games, with specific constraints on their quantities. Here's a step-by-step explanation of what this code does:

  1. User Input with Validation:

    • The user is asked to input the current number of books, DVDs, and games.
    • For books, the number entered must be between 0 and 30 inclusive. If the input doesn't meet this condition, the user is prompted again until a valid value is provided.
    • Similarly, for DVDs, the value must be between 0 and 15.
    • For games, the value must be between 0 and 10.
    • These checks ensure that the user provides valid quantities for each item.
  2. Cost Calculation Without Tax:

    • The program calculates the total cost of the inventory before taxes are applied:
      • Each book costs $2.25.
      • Each DVD costs $4.35.
      • Each game costs $5.00.
    • The formula for the total cost before tax is:
      cost_before_tax = books * 2.25 + dvds * 4.35 + games * 5.00
      
  3. Sales Tax Calculation:

    • A 6.5% sales tax is applied to the total cost before tax:
      sales_tax = cost_before_tax * 0.065
      
  4. Total Cost After Tax:

    • The program calculates the total cost after adding the sales tax:
      cost_after_tax = cost_before_tax + sales_tax
      
  5. Output:

    • The program prints:
      • The total cost before tax formatted to 2 decimal places.
      • The sales tax formatted to 2 decimal places.
      • The total cost after tax formatted to 2 decimal places.

Example:

If a user enters:

  • Books = 10
  • DVDs = 5
  • Games = 3

The calculations would be:

  • cost_before_tax = 10 * 2.25 + 5 * 4.35 + 3 * 5.00 = 22.50 + 21.75 + 15.00 = 59.25
  • sales_tax = 59.25 * 0.065 = 3.85125 (rounded to 3.85)
  • cost_after_tax = 59.25 + 3.85 = 63.10

The output:

Cost before tax: $59.25
Sales tax: $3.85
Cost after tax: $63.10
Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node