Foolproof.

--Originally published at Hackerman's house

It is usual that the programms that we use in our daily life require the interaction of the people, in this case there are occasions that an input is required to be given by the user, but how can the program now that the type of information the user gives can be used to perform a certain action.

A common case is when the program needs an integer to perform a mathematical operation but the user gives a string. In this case we can use a simple function. It is the try/except.

try except loop.JPG

In this program, if a number is given it will be stored as the user input. But if the data given is from other type like a string, it will ask again, and again. This loop will make sure that the user gives the correct data.

try-except

Thanks for reading me.

Here is some nice information about this process. http://www.101computing.net/number-only/

giphy