75.1k views
5 votes
Create a Python Shopping Cart Program that utilizes the starter code below. These are the requirements:

Must contain a MAIN FUNCTION with input statement(s).
Must calculate the GROSS COST.
Must calculate the NET COST.
Must include a tax rate of .0875.
Must have a SEPARATE function for calculating:
GROSS COST (which must also RETURN the final value).
NET COST (which must also RETURN the final value).

1 Answer

2 votes

Final answer:

To create a Python Shopping Cart Program that calculates the gross cost, net cost, and includes a tax rate, follow these steps: define the main function, create separate functions for calculating gross and net costs, call those functions in the main function, and print the results.

Step-by-step explanation:

In order to create a Python Shopping Cart Program that calculates the gross cost, net cost, and includes a tax rate, you can follow these steps:

  1. Define the main function and use input statements to get the necessary input from the user, such as the cost of items.
  2. Create a separate function called calculate_gross_cost that takes the cost of items as a parameter and multiplies it by 1 plus the tax rate to get the gross cost.
  3. Create another separate function called calculate_net_cost that takes the gross cost as a parameter and subtracts the tax from it to get the net cost.
  4. In the main function, call the calculate_gross_cost function to get the gross cost and store it in a variable.
  5. Next, call the calculate_net_cost function, passing the gross cost as a parameter, to get the net cost and store it in another variable.
  6. Finally, print out the gross cost and net cost.

Here's an example code implementation:

tax_rate = 0.0875
def calculate_gross_cost(cost):
return cost * (1 + tax_rate)

def calculate_net_cost(gross_cost):
return gross_cost - (gross_cost * tax_rate)
def main():
cost = float(input("Enter the cost of items: "))

gross_cost = calculate_gross_cost(cost)
net_cost = calculate_net_cost(gross_cost)
print("Gross cost: $", round(gross_cost, 2))
print("Net cost: $", round(net_cost, 2))
main()
User Nastasha
by
7.3k points