Improved console input and output
The pyinputplus
module
This module is used to simplify input validation by providing functions that ensure user input meets specified criteria, such as type, range, or format.
import pyinputplus as pyip
response = pyip.inputNum(prompt="Enter a number between 1 and 10: ", min=1, max=10)
print("You entered:", response)
response = pyip.inputYesNo(prompt="Do you want to continue? (yes/no): ")
if response == "yes":
print("You chose to continue.")
else:
print("You chose not to continue.")
The pprint
module
This module is used to format and print (pretty-print) complex data structures in a more readable and aesthetically pleasing way.
import pprint
data = {
"name": "Alice",
"age": 25,
"hobbies": ["reading", "hiking", "coding"],
"details": {
"location": "New York",
"languages": ["Python", "JavaScript"],
},
}
pprint.pprint(data)