@@ -13,6 +13,12 @@ def get_int(
1313 val_str = input (prompt ).strip ()
1414 if not val_str :
1515 if default is not None :
16+ if min_value is not None and default < min_value :
17+ print (f"❌ Default { default } is below minimum { min_value } ." )
18+ continue
19+ if max_value is not None and default > max_value :
20+ print (f"❌ Default { default } is above maximum { max_value } ." )
21+ continue
1622 return default
1723 print (error_empty )
1824 continue
@@ -40,6 +46,12 @@ def get_float(
4046 val_str = input (prompt ).strip ()
4147 if not val_str :
4248 if default is not None :
49+ if min_value is not None and default < min_value :
50+ print (f"❌ Default { default } is below minimum { min_value } ." )
51+ continue
52+ if max_value is not None and default > max_value :
53+ print (f"❌ Default { default } is above maximum { max_value } ." )
54+ continue
4355 return default
4456 print (error_empty )
4557 continue
@@ -52,103 +64,4 @@ def get_float(
5264 continue
5365 return val
5466 except ValueError :
55- print (error_invalid )
56-
57- def get_non_empty_string (
58- prompt : str ,
59- default : Optional [str ] = None ,
60- error_empty : str = "❌ Error: Input cannot be empty." ,
61- ) -> str :
62- while True :
63- val_str = input (prompt ).strip ()
64- if not val_str :
65- if default is not None :
66- return default
67- print (error_empty )
68- continue
69- return val_str
70-
71- def get_choice (
72- prompt : str ,
73- choices : List [str ],
74- default : Optional [str ] = None ,
75- error_empty : str = "❌ Error: Input cannot be empty." ,
76- error_invalid : Optional [str ] = None ,
77- ) -> str :
78- choices_lower = [c .lower () for c in choices ]
79- while True :
80- val_str = input (prompt ).strip ()
81- if not val_str :
82- if default is not None :
83- return default
84- print (error_empty )
85- continue
86- if val_str .lower () in choices_lower :
87- idx = choices_lower .index (val_str .lower ())
88- return choices [idx ]
89- if error_invalid is not None :
90- print (error_invalid )
91- else :
92- print (f"❌ Invalid selection. Please choose from: { ', ' .join (choices )} " )
93-
94- def get_yes_no (prompt : str , default : Optional [str ] = None ) -> bool :
95- while True :
96- val_str = input (prompt ).strip ().lower ()
97- if not val_str :
98- if default is not None :
99- return default .lower () in ['y' , 'yes' ]
100- print ("❌ Error: Input cannot be empty. Please enter 'y' or 'n'." )
101- continue
102- if val_str in ['y' , 'yes' ]:
103- return True
104- if val_str in ['n' , 'no' ]:
105- return False
106- print ("❌ Invalid choice. Please enter 'y' or 'n'." )
107-
108- def get_int_list (
109- prompt : str ,
110- min_len : Optional [int ] = None ,
111- max_len : Optional [int ] = None ,
112- error_empty : str = "❌ Error: Input cannot be empty." ,
113- error_invalid : str = "❌ Error: Please enter valid integers only." ,
114- ) -> List [int ]:
115- while True :
116- val_str = input (prompt ).strip ()
117- if not val_str :
118- print (error_empty )
119- continue
120- try :
121- val_list = [int (x ) for x in val_str .split ()]
122- if min_len is not None and len (val_list ) < min_len :
123- print (f"❌ Error: Please enter at least { min_len } numbers." )
124- continue
125- if max_len is not None and len (val_list ) > max_len :
126- print (f"❌ Error: Please enter at most { max_len } numbers." )
127- continue
128- return val_list
129- except ValueError :
130- print (error_invalid )
131-
132- def get_float_list (
133- prompt : str ,
134- min_len : Optional [int ] = None ,
135- max_len : Optional [int ] = None ,
136- error_empty : str = "❌ Error: Input cannot be empty." ,
137- error_invalid : str = "❌ Error: Please enter valid numbers only." ,
138- ) -> List [float ]:
139- while True :
140- val_str = input (prompt ).strip ()
141- if not val_str :
142- print (error_empty )
143- continue
144- try :
145- val_list = [float (x ) for x in val_str .split ()]
146- if min_len is not None and len (val_list ) < min_len :
147- print (f"❌ Error: Please enter at least { min_len } numbers." )
148- continue
149- if max_len is not None and len (val_list ) > max_len :
150- print (f"❌ Error: Please enter at most { max_len } numbers." )
151- continue
152- return val_list
153- except ValueError :
154- print (error_invalid )
67+ print (error_invalid )
0 commit comments