Skip to content

Instantly share code, notes, and snippets.

@BlackVikingPro
Created January 11, 2017 02:58
Show Gist options
  • Save BlackVikingPro/7e39db444991b950a56e7f99968bb5aa to your computer and use it in GitHub Desktop.
Save BlackVikingPro/7e39db444991b950a56e7f99968bb5aa to your computer and use it in GitHub Desktop.
Randomize a sentence's casing in Python!
#! /usr/bin/env python
""" Random String Casing ~~ by Willy Fox (BlackVikingPro) """
import sys, random
try:
tmp = sys.argv[1]
pass
except IndexError:
if sys.argv[0].startswith('./'):
print "Randomize text casing in Python! By: \033[31mWilly Fox\033[0m\n\nSyntax: %s <string/sentence>\n" % sys.argv[0]
else:
print "Randomize text casing in Python! By: \033[31mWilly Fox\033[0m\n\nSyntax: ./%s <string/sentence>\n" % sys.argv[0]
except KeyboardInterrupt:
print " Exiting Cleanly..."
except Exception as e:
print "Well, this is embarrassing... ", e
def ranCase(word):
leng = len(word)
nword = ""
for case in range(0, leng):
if random.randint(0, 1) == 1:
letter = word[case].upper() + word[(leng + 1):]
else:
letter = word[case].lower() + word[(leng + 1):]
pass
nword = nword + letter
pass
return nword
pass
argLeng = len(sys.argv)
word = ""
sentence = ""
for index in xrange(1,argLeng):
word = ranCase(sys.argv[index])
sentence = sentence + word + " "
# print ranCase(sys.argv[index])
pass
print sentence
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment