-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
47 lines (37 loc) · 1.38 KB
/
Copy pathtest.py
File metadata and controls
47 lines (37 loc) · 1.38 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import random
def wonky_text(input_text):
return ''.join(c.upper() if i % 2 == 0 else c.lower() for i, c in enumerate(input_text))
def reverse_text(input_text):
return input_text[::-1]
def randomize_case(input_text):
return ''.join(random.choice([c.upper(), c.lower()]) for c in input_text)
def l33t_speak(input_text):
l33t_dict = {'a': '4', 'e': '3', 'i': '1', 'o': '0', 's': '5', 't': '7'}
return ''.join(l33t_dict.get(c.lower(), c) for c in input_text)
def apply_transformation(text, transformation):
transformations = {
'1': ('Wonky', wonky_text),
'2': ('Reversed', reverse_text),
'3': ('Random Case', randomize_case),
'4': ('L33t Speak', l33t_speak)
}
name, func = transformations.get(transformation, ('Invalid', lambda x: x))
return name, func(text)
# Main program loop
while True:
print("\nText Transformer")
print("1. Wonky Text")
print("2. Reverse Text")
print("3. Random Case")
print("4. L33t Speak")
print("5. Quit")
choice = input("Choose a transformation (1-5): ")
if choice == '5':
print("Goodbye!")
break
if choice not in ['1', '2', '3', '4']:
print("Invalid choice. Please try again.")
continue
user_input = input("Enter your text: ")
name, result = apply_transformation(user_input, choice)
print(f"{name} output: {result}")