+ 2
Why is my code not working in python?
Everytime I use this code. It says there is an error. i also can not find what is wrong with it! PLS HELP! https://sololearn.com/compiler-playground/c55T0n7VxtP4/?ref=app
3 Antworten
+ 5
It worked fine for me.
When the input box pops up, write your items like this:
orange
apple
Each on a new line.
*edit*
Don't post the same question more than once. It's spamming the thread.
+ 4
while the code works, the structure and syntax could be improved upon.
+ 4
this is the corrected code
# Welcome message
print("Welcome to the supermart! There are two options to buy: Watermelon and Oranges.")
print("Choose what you want.")
# Initialize the shopping cart
shopping_cart = []
def add_to_cart():
# Ask the user what they want to add
choice = input("Enter 'orange' for oranges or 'watermelon' for watermelon: ").lower()
# Check what the user wants and add to the cart
if choice == "orange":
shopping_cart.append("orange")
print("Shopping items: Orange added to cart.")
elif choice == "watermelon":
shopping_cart.append("watermelon")
print("Shopping items: Watermelon added to cart.")
else:
print("Invalid choice! Please choose 'orange' or 'watermelon'.")
# Add items to the cart
add_to_cart()
def confirm_order():
# Display the items the user has ordered
print("You have ordered:", shopping_cart)
# Ask for confirmation of the order
confirmation = input("Do you want to confirm your order? (yes/n