Skip to content

Instantly share code, notes, and snippets.

@csiknor
Last active February 21, 2016 13:31
Show Gist options
  • Select an option

  • Save csiknor/144595f87b4318d6fa53 to your computer and use it in GitHub Desktop.

Select an option

Save csiknor/144595f87b4318d6fa53 to your computer and use it in GitHub Desktop.
This python script reads user input and piggifies it after validation. Created for a Python assignment on Codecademy.
def read():
word = raw_input("Gimme your word:")
if len(word) == 0:
print "You must say something"
return read()
elif not word.isalpha():
print "It's not a word, honey! (No spaces, numbers allowed...)"
return read()
else:
return word
def piggify(s):
if len(s) == 1:
return s + "ay"
else:
return s[1:] + s[0] + "ay"
print piggify(read().lower())
@csiknor
Copy link
Author

csiknor commented Feb 21, 2016

This is what they suggest as a solution...

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
    print "I'll use '%s' to translate" % (original)
    word = original.lower()
    first = word[0]
    new_word = word[1:] + first + pyg
    print "Translation: " + new_word
else:
    print "You've not entered a thing... " + pyg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment