MCPcopy Create free account
hub / github.com/geekcomputers/Python / get_valid_input

Function get_valid_input

Tic-Tac-Toe Games/tic-tac-toe1.py:47–56  ·  view source on GitHub ↗

Get a valid integer input between 0 and 2.

(prompt: str)

Source from the content-addressed store, hash-verified

45
46
47def get_valid_input(prompt: str) -> int:
48 """Get a valid integer input between 0 and 2."""
49 while True:
50 try:
51 value = int(input(prompt))
52 if 0 <= value < 3:
53 return value
54 print("Invalid input: Enter a number between 0 and 2.")
55 except ValueError:
56 print("Invalid input: Please enter an integer.")
57
58
59def main() -> None:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected