Created
January 11, 2017 02:58
-
-
Save BlackVikingPro/7e39db444991b950a56e7f99968bb5aa to your computer and use it in GitHub Desktop.
Randomize a sentence's casing in Python!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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