0

I wrote the following code which is a slight variation to yours:

shopping_cart = ['pen', 'paper ', 'ink '] #items in shopping cart
out_of_stock = ['pen', 'ink']  #items out of stock

for item in shopping_cart:
    if item in out_of_stock:
        print ("Sorry, " + item + " is out of stock.")
    else:
        print ("Adding " + item + " to your shopping cart")

print ("Your order is complete.")

but for some reason it only returns one item out of stock, when there are two:

Sorry, pen is out of stock. Adding paper to your shopping cart Adding ink to your shopping cart Your order is complete.

What am I doing wrong?

1 Answer 1

1

You've got an extra space in the 'ink ' string on the first line. 'ink' != 'ink '

Sign up to request clarification or add additional context in comments.

1 Comment

ha ha! Thank you Jerfov2, that's what it was. Sometimes it's the simplest thing that drives you crazy!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.