Input and Exception Tips
Explore how to properly strip user input to avoid common issues and handle exceptions effectively by isolating error-prone statements and targeting specific errors. Understand best practices to build safer Python programs.
We'll cover the following...
Strip user input
Many developers claim to know how to read user input from the console.
But there’s a twist: when asked to enter something, a user may add extra spaces before or after the requested information, intentionally or otherwise. An evil user may insert additional spaces in the middle, too, but handling that kind of user is beyond the scope of this course.
If we use the input() function to request a number, we will further call int() or float(), both of which are trained to discard the heading and trailing spaces. This is not so with general ...