Posts

Intro to Python Programming: Exceptions and Pickling

My goal here is to create a simple example for using Exception Handling and Pickling in Python. For the Exception handling I created a simple program that asks for a dog’s age in human years and returns the dog’s age in “dog” years. The user needs to enter a whole number that is positive. If the user fails to enter a positive whole number then the error exceptions catch the mistake and print an error message. Afterwards you will see a simple example of the Pickling technique which stores a dictionary, then loads the data and finally prints the result to display the binary information as a normal dictionary string once again. Let’s begin with the Exception handling. There are two error exceptions, the first one recognizes if the user has entered a negative value with the help of a calculation which generates a “ZeroDivisionError” if the value entered is negative. Its simpler than it looks; the denominator (bottom of the division equation) is the sum of the original value plus its ab
Recent posts