Handling Exceptions in Python
Not Equals Operator
# elif Statement pet_type = "fish" if pet_type == "dog": print("You have a dog.") elif pet_type == "cat": print("You have a cat.") elif pet_type == "fish": # this is performed print("You have a fish") else: print("Not sure!")
elif statement allows for continued checks to be performed after an initial
if statement. An
elif statement differs from the
else statement because another expression is provided to be checked, just as with the initial
If the expression is
True, the indented code following the
elif is executed. If the expression evaluates to
False, the code can continue to an optional
else statement. Multiple
elif statements can be used following an initial
if to perform a series of checks. Once an
elif expression evaluates to
True, no further
elif statements are executed.
We’ve learned about and explored a powerful tool in Python — control flow! It’s so powerful, in fact, that it can be used to tell someone’s fortune.
Use your knowledge of control flow to create a program that will help Sal's customers get the best deals on all their shipping needs.