-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocessor.py
More file actions
27 lines (22 loc) · 739 Bytes
/
Copy pathprocessor.py
File metadata and controls
27 lines (22 loc) · 739 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import json
class InputValidationError(Exception):
pass
def validate_input(user_input):
if not isinstance(user_input, str) or not user_input:
raise InputValidationError('Input must be a non-empty string.')
def process_user_input(user_input):
validate_input(user_input)
# Process the valid input
return {'result': user_input.upper()}
def main():
while True:
user_input = input('Enter some text (or type exit to quit): ')
if user_input.lower() == 'exit':
break
try:
result = process_user_input(user_input)
print(json.dumps(result))
except InputValidationError as e:
print(f'Error: {e}')
if __name__ == '__main__':
main()