How to Read Python Input as Integers

If you’ve ever coded an interactive text-based application in Python, then you’ve probably found that you need a reliable way of asking the user for integers as input. It’s not enough simply to display a prompt and then gather keystrokes. You must check that the user’s input really represents an integer. If it doesn’t, then your code must react appropriately—typically by repeating the prompt.

In this tutorial, you’ll learn how to create a reusable utility function that’ll guarantee valid integer inputs from an interactive user. Along the way, you’ll learn about Python’s tools for getting a string from the console and converting that string into an integer.

Whenever you’re writing a program that interacts with the keyboard, you must

 

 

 

To finish reading, please visit source site