139k views
4 votes
your program will get from the user how man of each item they want to purchase and whether they want in store pick up or they would like their items shipped. Shipping is a flat rate. The program will display a menu showing your name and the names and prices of the items you wish to sell. The program will calculate and display the totals for each item sold, the shipping cost, and the total due. *Need code using Python

1 Answer

5 votes

Final answer:

To create a program in Python for purchasing items, you can follow steps such as creating a dictionary for item names and prices, prompting the user for quantities and shipping preferences, calculating totals, and displaying the results.

Step-by-step explanation:

Python Program for Purchasing Items

To write a program in Python for purchasing items, you can follow these steps:

  1. Create a dictionary to store the item names and prices.
  2. Prompt the user to enter the quantity of each item they want to purchase and whether they want in-store pickup or shipping.
  3. Calculate the total for each item by multiplying the quantity by its price.
  4. Sum up the totals of all items to get the subtotal.
  5. Determine the shipping cost based on the user's choice.
  6. Add the subtotal and shipping cost to get the total due.
  7. Display the totals for each item, the shipping cost, and the total due.

Here is an example code:

items = {'Item 1': 10, 'Item 2': 20, 'Item 3': 30}
quantities = {}

# Prompt for inputs
for item in items.keys():
quantities[item] = int(input(f'Enter quantity for {item}: '))

shipping_choice = input('Enter your shipping choice (pickup/ship): ')

# Calculate totals
subtotal = 0
total_due = 0

for item, quantity in quantities.items():
total = items[item] * quantity
subtotal += total
print(f'Total for {item}: {total}')

# Calculate shipping cost
if shipping_choice == 'pickup':
shipping_cost = 0
else:
shipping_cost = 5

# Calculate total due
total_due = subtotal + shipping_cost

# Display results
print(f'Subtotal: {subtotal}')
print(f'Shipping Cost: {shipping_cost}')
print(f'Total Due: {total_due}')

User FreeBird
by
8.0k points