Refining and redefining solutions
If we look at algorithms long enough, we can always find ways to refine them and redefine them. Think about how many updates we get for apps on our phones. Someone is always playing with the apps, making them more secure, adding levels to games, updating the art files, and so on. As programmers/coders, we are always trying to make our work better.
We are going to start this section with an algorithm. The following program prints out the names of three pets:
ch7_pets1.py
cat = "Whiskers" dog = "King Kong" bird = "Pirate" print("The cat's name is " + cat + ", the dog's name is " + dog + \ ", and the bird's name is " + bird + ".")
This simple code has everything within it, so there's no user input this time. You can see the \
character used after dog +
in the print()
command. This backslash allows us to add the remaining...