Validated user input in Python. Mastery 29.

If you’re expecting an specific in Python, you can validate the input of the user  by comparing that input to the input you expect.

Example:

 

This program calculates the factorial.

At the end, it asks the user to input if he wants to try another. If the user types y, then, the program executes again. If n or different than y, the program ends. That’s the reason why the main program executes after the while (x==”y”) condition.

CC BY 4.0 Validated user input in Python. Mastery 29. by Ismael Lizárraga is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.