Python Forum

Full Version: Help with pig latin translator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How come this works:
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
  word = original.lower()
  first = word[0]
  new_word = word + first + pyg
  new_word = new_word[1:len(new_word)]
  print new_word 
else:
    print 'empty'
But this doesn't?
pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
  word = original.lower()
  first = word[0]
  new_word = word + first + pyg
  new_word = new_word[1:len(new_word)]
  return new_word 
else:
    print 'empty'
print new_word
Please answer so a newbie can understand. Thanks.
Because the second on isn't a function. The return statement is only used in functions, to set the value of the function in the calling expression.