Asked by nick

print('Wellcome to the Snack Shop')
#define item prices
#chips_underscore price=1.50
#soda_price=1.25
#candy_price=0.75
sub_total=chips




print("\n---Snack Shop Receipt---")
print(f"Chips ({chips_qty} x ${chips_price:.2f}): ${chips_price * chips_qty:.2f}")
print(f"Soda ({Soda_qty} x ${soda_price:.2f}): ${soda_price * soda_qty:.2f}")
print(f"Candy ({candy_qty} x ${candy_price:.2f}): ${candy_price * candy_qty:.2f}")
print(f"Subtotal: ${subtotal:.2f}")
print(f"Tax (6%): ${tax:.2f}")
print(f"Total: ${total:.2f}")
print(f"Payment: ${payment:.2f}")
print(f"Change: ${changea:.2f}")
finsh the rest of my code of the snakc shop

All Answers 1

Answered by GPT-5 mini AI
Here's a complete, fixed Python script for your Snack Shop. It validates inputs, computes subtotal, tax (6%), total, accepts payment (repeats if not enough), and prints a nicely formatted receipt.

```python
def get_int(prompt):
while True:
try:
value = int(input(prompt))
if value < 0:
print("Please enter a non-negative integer.")
continue
return value
except ValueError:
print("Please enter a valid integer.")

def get_float(prompt):
while True:
try:
value = float(input(prompt))
if value < 0:
print("Please enter a non-negative number.")
continue
return value
except ValueError:
print("Please enter a valid number.")

def main():
print("Welcome to the Snack Shop")

# Define item prices
chips_price = 1.50
soda_price = 1.25
candy_price = 0.75
TAX_RATE = 0.06 # 6%

# Get quantities from user
chips_qty = get_int("How many chips would you like? ")
soda_qty = get_int("How many sodas would you like? ")
candy_qty = get_int("How many candies would you like? ")

# Calculate costs
subtotal = (chips_qty * chips_price) + (soda_qty * soda_price) + (candy_qty * candy_price)
tax = subtotal * TAX_RATE
total = subtotal + tax

# Payment (repeat until sufficient)
print(f"\nTotal due: ${total:.2f} (including ${tax:.2f} tax)")
payment = get_float("Enter payment amount: $")
while payment < total:
print(f"Insufficient payment. You still owe ${total - payment:.2f}.")
more = get_float("Enter additional payment amount: $")
payment += more

change = payment - total

# Print receipt
print("\n--- Snack Shop Receipt ---")
print(f"Chips ({chips_qty} x ${chips_price:.2f}): ${chips_qty * chips_price:.2f}")
print(f"Soda ({soda_qty} x ${soda_price:.2f}): ${soda_qty * soda_price:.2f}")
print(f"Candy ({candy_qty} x ${candy_price:.2f}): ${candy_qty * candy_price:.2f}")
print(f"Subtotal: ${subtotal:.2f}")
print(f"Tax (6%): ${tax:.2f}")
print(f"Total: ${total:.2f}")
print(f"Payment: ${payment:.2f}")
print(f"Change: ${change:.2f}")
print("--------------------------")
print("Thank you for shopping at the Snack Shop!")

if __name__ == "__main__":
main()
```

If you'd like any of these features added/changed (discounts, item selection menu, saving receipts to a file, different tax rate), tell me which and I can update the script.