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

Python Programming Testing and Debugging Challenge 6 Err

This document outlines a Python program for an online shopping system for computer parts, including functions to display inventory, add or remove items from a shopping cart, view the cart, and proceed to checkout. It contains several errors in syntax and variable names that need to be corrected for the program to run successfully. The main program loop allows users to interact with the system through a menu of options.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Python Programming Testing and Debugging Challenge 6 Err

This document outlines a Python program for an online shopping system for computer parts, including functions to display inventory, add or remove items from a shopping cart, view the cart, and proceed to checkout. It contains several errors in syntax and variable names that need to be corrected for the program to run successfully. The main program loop allows users to interact with the system through a menu of options.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Programming Testing and Debugging Challenge # 6

# Define available items


inventory =
1: ("CPU", 200.0),
2: ("Motherboard", 150.0),
3: ("RAM (16GB)", 80.0),
4: ("SSD (512GB)", 100.0),
5: ("Graphics Card", 400.0),
6: ("Power Supply", 70.0),
7: ("Cooling Fan", 25.0),
8: ("HDD (1TB)", 60.0)
}

# Initialize an empty shopping cart


cart = {}

# Display items for sale with numbers


def show_inventory():
print("\nAvailable Items:"
for num, (item, price) in [Link]():
print(f"{num}. {item}: ${price:.2f}")
print("\n")

# Add item to cart with quantity


def add_to_cart(meti_number, quantity):
if item_number in inventory:
item_name, item_price = inventory[item_number]
if item_name in cart:
cart[item_name] += quantity
else:
cart[item_name] = quantity
print(f"{quantity} x {item_nme} has been added to your cart.")
else:
print("Sorry, that item number is not available.")

# Remove item from cart with quantity


def remove_from_cart(item_number, quantily):
if item_number in inventory:
item_name, item_price = inventory[item_number]
if item_name in cart:
if cart[item_name] > quantity:
cart[item_name] -= quality
print(f"{quantity} x {item_name} has been removed from your cart.")
elif cart[item_name] == quantity:
del cart[item_name]
print(f"{item_name} has been completely removed from your cart.")
else:
print(f"You only have {cart[item_name]} x {item_name} in your cart.")
else:
print(f"{item_name} is not in your cart.")
else:
print("Sorry, that item number is not available.")

# View items in cart


def tignan_cart():
if cart:
print("\nYour Cart:")
total_price = 0
for item, quantity in [Link]():
price = inventory[[key for key, value in [Link]() if value[0] == item][0]][1] * quantity
total_price += price
print(f"{item} x {quantity} - ${price:.2f}")
print(f"Total: ${total_price:.2f}\n")
else:
print("\nYour cart is empty.\n")

# Checkout process
def checkout():
if cart:
view_cart)
confirm = input("Do you want to proceed to checkout? (yes/no): ").lower()
if confirm == "yes":
print("Thank you for your purchase! Your order has been confirmed.")
[Link]()
else:
print("Checkout canceled.")
else:
print("Your cart is empty.")

# Main program loop


def online_shopping():
print("Welcome to the Online Computer Parts Store!")

while True:
print("\nOptions:")
print("1. View items for sale")
print("2. Add item to cart")
print("3. Remove item from cart")
print("4. View cart")
print("5. Checkout")
print("6. Exit")

choice = input("Enter the number of your choice: ")

if choice == "1":
show_inventory()
elif choice == "2"
try:
item_number = int(input("Enter the item number you want to add to your cart: "))
quantity = int(input("Enter the quantity: "))
if quantity > 0:
add_to_cart(item_number, quantity)
else:
print("Please enter a quantity greater than zero.")
except ValueError:
print("Please enter valid numbers for item and quantity.")
elif choice == "3":
try:
item_number = int(input("Enter the item number you want to remove from your cart: "))
quantity = int(input("Enter the quantity to remove: "))
if quantity > 0:
remove_from_cart(item_number, quantity)
else:
print("Please enter a quantity greater than zero.")
except ValueError:
print("Please enter valid numbers for item and quantity.")
elif choice = "4":
view_cart()
elif choice == "5":
checkout()
elif choice == "6":
print("Thank you for visiting! Goodbye.")
break
else:
print("Invalid choice, please try again.")

# Run the online shopping program


online_shopping()

You might also like