--Originally published at Elu's Blog
As programmers we would like that the user always does what they are told so the program runs perfectly. Sadly this doesn’t happen all the time, so we have to create fail-safes in order for the program runs well.
Here is an example:
As we can see in the image above I am telling the user to enter a positive integer, but what if the user doesn’t want? As we can also see, if the user enters a negative integer, the while loop will repeat until it gets a positive integer.
This is just a simple example and a reminder that we a s programmers always have to think about ‘what could the user input in order for the program to fail?’
Here is an alternative explanation:
Validate Users input in Python3 by Eric Israel Reyes Cruz