using IF-statement with List

USING IF-statement with List:
You can do some interesting work when you combine lists and if statements. You can watch for special values that need to be treated differently than other values in the list. You can manage changing conditions efficiently, such as the availability of certain items in a restaurant throughout a Shift. You can also begin to prove that your code works as you expect it to in all possible situations.

For example:

requested_toppings={'mushrooms','green peppers','extra cheese'}
print("Adding"+requested_toppings+".")
print("\nFinished making your pizza!")

OUTPUT:
Adding mushrooms.
Adding green peppers.
Adding extra cheese.

Finished making your pizza!

Using multiple Lists:
the following example defines two lists. The first is a list of available topping at the pizzeria, and the second is the list of toppings that the user has requested. This time, each item in requested_topping is checked against the lists of available toppings before it’s added to the pizza:

1.Example of multiple Lists

available_toppings=['mushrooms','olives','green peppers','pepperoni','pineapple','extra cheese']
requested_toppings=['mushrooms','french fries','extra cheese']
if
 requested_topping in requested_toppings:
print("Adding"+requested_topping+".")
else:
print("Sorry,we don't have"+requested_topping+".")
print("\nFinished making your pizza!")

OUTPUT:
Adding mushrooms.
Sorry,we don't have french fries.
Adding extra cheese.

Finished making your pizza!
Translate »