Thank you. That makes sense.
I have another question now:
Example 2 says the first two purchases are both in stock and not in stock. Why is the "else" statement working unreliably?
I'm guessing else only works with the last if statement, not every if statement in the for loop?
I have another question now:
main_site = ['mayo', 'ketchup', 'mustard', 'milk', 'eggs'] off_site = ['cocoa', 'flour', 'salt', 'bread', 'butter'] purchases = ['ketchup', 'mustard', 'bread', 'butter', 'hot dogs'] print("\n") for purchase in purchases: print('\n') print(purchase) if purchase in main_site or purchase in off_site: print("That item is in stock!") if purchase in main_site: print("The item can be picked up today.") if purchase in off_site: print("The item can be delivered in two to five days.") if purchase not in main_site and purchase not in off_site: print("Sorry, that item is not in stock.") print("We hope you purchase from us again!")
main_site = ['mayo', 'ketchup', 'mustard', 'milk', 'eggs'] off_site = ['cocoa', 'flour', 'salt', 'bread', 'butter'] purchases = ['ketchup', 'mustard', 'bread', 'butter', 'hot dogs'] print("\n") for purchase in purchases: print('\n') print(purchase) if purchase in main_site or purchase in off_site: print("That item is in stock!") if purchase in main_site: print("The item can be picked up today.") if purchase in off_site: print("The item can be delivered in two to five days.") else: print("Sorry, that item is not in stock.") print("We hope you purchase from us again!")Example 1 works as expected.
Example 2 says the first two purchases are both in stock and not in stock. Why is the "else" statement working unreliably?
I'm guessing else only works with the last if statement, not every if statement in the for loop?