0% found this document useful (0 votes)
10 views2 pages

Etsy Shopping Cost Calculator

The document is a Python script for a shopping application that prompts users to input up to four items and their prices. It calculates the subtotal, tax, and shipping costs, and then displays the order summary with the total amount. The program concludes by thanking the user for their shopping experience.

Uploaded by

timmyk1101
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Etsy Shopping Cost Calculator

The document is a Python script for a shopping application that prompts users to input up to four items and their prices. It calculates the subtotal, tax, and shipping costs, and then displays the order summary with the total amount. The program concludes by thanking the user for their shopping experience.

Uploaded by

timmyk1101
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

from math import *

def main():
print("Time to shop Etsy!")
print("")
print("Your order:")
print("")
print("Item Cost")

nameOne = input("What is your first item?")


nameOneSlice = nameOne[0:18]
lengthOne = len(nameOneSlice)+1
spaces = [" "," "," "," "," "," "," "," "," ","
"," "," "," "," "," ","
"," "," "," "]
itemOne = float(input("What is the price of your first item?"))
print(nameOneSlice + ": " + spaces[19-lengthOne] + "$" + str(round(itemOne,
2)))

nameTwo = input("What is your second item?")


nameTwoSlice = nameTwo[0:18]
lengthTwo = len(nameTwoSlice)+1
itemTwo = float(input("What is the price of your second item?"))
print(nameTwoSlice + ": " + spaces[19-lengthTwo] + "$" + str(round(itemTwo,
2)))

nameThree = input("What is your third item?")


nameThreeSlice = nameThree[0:18]
lengthThree = len(nameThreeSlice)+1
itemThree = float(input("What is the price of your third item?"))
print(nameThreeSlice + ": " + spaces[19-lengthThree] + "$" +
str(round(itemThree, 2)))

nameFour = input("What is your fourth item?")


nameFourSlice = nameFour[0:18]
lengthFour = len(nameFourSlice)+1
itemFour = float(input("What is the price of your fourth item?"))
print(nameFourSlice + ": " + spaces[19-lengthFour] + "$" + str(round(itemFour,
2)))

Subtotal = itemOne+itemTwo+itemThree+itemFour
Tax = Subtotal*0.065+5.99
Shipping = 5.99
totalPrice = itemOne+itemTwo+itemThree+itemFour

subRound = round(Subtotal, 2)
taxRound = round(Tax, 2)
totalRound = round(totalPrice, 2)

print("--------------------------")
print(" Subtotal: " + " $" + str(subRound))
print(" Tax: " + " $" + str(taxRound))
print(" Shipping: " + " $" + str(Shipping))
print(“ Order total: “ + “ $” + str(totalRound))

print("")
print("Thanks for shopping!")

main()

Common questions

Powered by AI

By separating the arithmetic operations into distinct steps, such as computing subtotal, tax, and shipping individually, the script improves readability, making the code clearer and more approachable for debugging. This approach allows for straightforward troubleshooting of single erroneous computations, supports testing each step independently, and provides meaningful variable names that convey each component's purpose, enhancing maintainability.

Currently, the shipping cost is directly added as a fixed value in the tax calculation, which limits flexibility to handle scenarios such as multiple shipping options or international rates. Improvements could involve modularizing the shipping calculation into a separate function or class method that takes parameters like distance or service level, allowing dynamic adjustment based on specific shopping operations or user selections.

The length of spaces is determined by calculating the difference between a constant space length (19) and the length of the sliced item name plus one. This calculation effectively aligns each item's price output by prepping blank spaces to fill the gap. The programmed spaces list contains numerous blank spaces used to facilitate alignment in the console output by slicing it to (19-length) characters, where length includes the sliced name.

The program slices each item name to a maximum of 18 characters using slicing syntax (name[0:18]). This length limit is critical to maintain consistent formatting in console output, ensuring item names and their prices align neatly below the headers in the printed receipt format. This alignment is necessary for the receipt's readability and to avoid errors in visual presentation.

Using the 'round' function in financial calculations prevents numerical errors due to floating-point precision, ensuring display consistency and accuracy in financial data. The script applies 'round' to subtotal, tax, and total calculations, ensuring these values are formatted to two decimal places before printing. This rounding is crucial for user clarity and precision in currency representation.

The 'Tax' value in the program augments the calculated subtotal to account for applicable sales tax. It is computed by multiplying the subtotal by a tax rate of 0.065 and adding a constant shipping fee of 5.99. This ensures the total price accurately reflects both the item cost with tax and the fixed transportation cost for delivery.

Defining a 'main' function encapsulates the core logical sequence of the program, aiding readability and modular execution. It distinguishes the setup and execution phases, allowing the program to be initiated with a simple call, improves organization and maintainability, and supports enhancements such as adding command-line argument parsing or integration into larger systems with distinct entry points.

Console print methods offer simplicity and direct feedback for debugging and user interaction, enabling real-time monitoring of script operations and output verification. However, limitations include the lack of GUI or web interface capabilities, reducing user engagement, and manual operation constraints. Transitioning to file output or interfacing with a GUI library could address these interactive limitations and enhance user experience.

Issues can arise from the script assuming all item prices are valid float values without validation checks, leading to program errors if non-numeric input is entered. Errors could be mitigated by implementing exception handling with try-except blocks around the `float(input())` calls, ensuring only valid numerical input is processed, and prompting error messages or reprompting input for invalid entries.

The procedural style and hard-coded operations limit scalability and ease of adding functions like dynamic tax rates or item categories. Transitioning toward an object-oriented design by encapsulating items, orders, and calculations in classes would enhance extensibility, aiding scalability into more complex systems. This restructuring would also facilitate reusability and integration of extended features such as promotional discounts or bulk ordering logic.

You might also like