3) a. Conditional Statements Examples




Jaspurr Mewoly wants to rule the world. She doesn’t seem to care for the fact that she’s just 7 months old, nor that she is fat and cannot feed herself anything but delicious fresh fish. She is a mighty kitten on a mission: unite all the cats of the world, make them join the ‘Militant Alliance Of the World Felines (MAOWf)’and fight altogether for global feline justice. Jaspurr needs first to separate felines from non-felines on a python program. Can you help her decide if a given animal is a cat or not?
Write a simple code that prints out the string “Welcome to MAOWf!” if ‘animal’ is ‘feline’, otherwise it does nothing.

1
2
3
Output:
Please enter your pet animal feline
Welcome to MEAOWf




Nice – Jaspurr’s if conditional statement has worked and all felines are nicely greeted. However, she is missing out on cats and kittens. Amend the previous code so that it prints “Welcome to MAOWf” if “animal” is “feline”, “cat” or”kitten”.

1
2
3
Output:
Please enter your what animal your pet is. cat
Welcome to MEAOWf




Make the above conditional statement print “Sorry, we don’t know you.” if “animal” is not “feline”, “cat” or “kitten”.

1
2
3
Output:
Please enter your what animal your pet is. dog
Sorry, we don't know you




The dogs are fighting back! Some of them are disguised as cats and pretend to be friends! Complement the above code so that it prints “Dogs go away!” if “animal” is “dog”.

1
2
3
Output:
Please enter your what animal your pet is. dog
Dogs begone!