/
spongetext.py
49 lines (37 loc) · 1.12 KB
/
spongetext.py
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
48
49
# sPoNgEtExT, bY aL sWeIGaRt Al@iNvEnTwItHpYtHoN.cOm
# Translates English messages into sPOnGEtExT.
import random
try:
import pyperclip
except ImportError:
pass # It's not a big deal if pyperclip is not installed.
def englishToSpongetext(message):
spongetext = ''
useUpper = False
for character in message:
if not character.isalpha():
spongetext += character
continue
if useUpper:
spongetext += character.upper()
else:
spongetext += character.lower()
useUpper = not useUpper # Flip the case.
# Randomly flip the case again in 1 in 10 characters.
if random.randint(1, 10) == 1:
useUpper = not useUpper
return spongetext
def main():
print('''sPoNgEtExT
bY aL sWeIGaRt Al@iNvEnTwItHpYtHoN.cOm
eNtEr YoUr MeSsAgE:''')
spongetext = englishToSpongetext(input())
print()
print(spongetext)
try:
pyperclip.copy(spongetext)
print('(cOpIed SpOnGeTexT to ClIpbOaRd.)')
except:
pass # Do nothing if pyperclip wasn't installed.
if __name__ == '__main__':
main()