Virtual Pet

The same principles as menus and choices are demonstrated here in virtual pet. 

Two definitions have been made that take one parameter (how)  

Then a menu and a get menu choice definition.

The definition to handle the choice from the menu - sent to this as a parameter called choice.

Finally the main() definition to make the program work.   Uses a while loop to run the program until the user wants to stop.  - line 41 below is where the program starts by calling the main definition. 

You can obviously add more options to the menu and the handle the choice to give your pet more actions. 

Some people have wanted to add in a health for the pet which goes up if they eat and down if not.   First thing to do is add a GLOBAL variable just before you call main 


Next I amended main to include a while loop - see where the variable is referenced here with the keyword global

Next in each of the definitions where you want to change health add the line global health and then adjust health as required - in this case I increase it if the pet eats

 And in bark - decrease health