File tree Expand file tree Collapse file tree
games/Number-Guessing-Game Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import sys
21import os
32import random
3+ import sys
44
5- # Add project root to sys.path
5+ # Standardized path resolution to point to project root securely
66if "__file__" in globals ():
7- sys .path .append (os .path .abspath (os .path .join (os .path .dirname (__file__ ), ".." , ".." ) ))
7+ project_root = os .path .abspath (os .path .join (os .path .dirname (os .path .abspath (__file__ )) , ".." , ".." ))
88else :
9- sys .path .append (os .path .abspath (os .getcwd ()))
9+ project_root = os .path .abspath (os .getcwd ())
10+
11+ if project_root not in sys .path :
12+ sys .path .append (project_root )
13+
1014from utils .validation import get_choice , get_int
1115
1216# Game constants
1822CLOSE_THRESHOLD = 10
1923NOT_CLOSE_THRESHOLD = 20
2024
25+
2126def main () -> None :
2227 print ("🎯 Welcome to the Number Guessing Game!\n " )
2328
@@ -58,6 +63,7 @@ def main() -> None:
5863 error_invalid = "⚠️ Invalid input. Please enter a whole number."
5964 )
6065
66+ # Constraint check before incrementing attempts to avoid penalties
6167 if not (MIN_NUMBER <= guess_num <= MAX_NUMBER ):
6268 print (f"⚠️ Enter a number between { MIN_NUMBER } and { MAX_NUMBER } ." )
6369 continue
@@ -108,5 +114,6 @@ def main() -> None:
108114 print ("👋 Goodbye." )
109115 break
110116
117+
111118if __name__ == "__main__" :
112119 main ()
You can’t perform that action at this time.
0 commit comments