Python Forum
Help with pig latin translator
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with pig latin translator
#1
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.
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  non-latin characters in console from clipboard Johanson 3 656 Oct-26-2023, 10:10 PM
Last Post: deanhystad
  (python) Can i get some help fixing a English to Morse translator? Pls AlexPython 7 1,540 Sep-12-2022, 02:55 AM
Last Post: AlexPython
  "If Len(Word) == 0" Code Block in Pig Latin Program new_coder_231013 3 2,017 Jan-02-2022, 06:03 PM
Last Post: deanhystad
  i want to write symbole as varibales in python to make translator rachidel07 9 3,411 Feb-03-2021, 09:57 PM
Last Post: nilamo
  Pressing non-latin characters? Murlog 0 1,504 Jul-25-2020, 03:10 PM
Last Post: Murlog
  letter translator (or someting) Obsilion 4 2,421 Apr-28-2020, 12:40 PM
Last Post: deanhystad
  I want to filter out words with one letter in a string (pig latin translator) po0te 1 2,070 Jan-08-2020, 08:02 AM
Last Post: perfringo
  Trouble with Regex Translator skrivver99 3 2,718 Dec-15-2018, 03:55 PM
Last Post: Gribouillis
  Output discrepancy when building Translator skrivver99 17 6,527 Nov-26-2018, 01:22 AM
Last Post: ichabod801
  PigLatin Sentence Translator Help 2skywalkers 7 5,750 Jun-23-2018, 12:46 AM
Last Post: 2skywalkers

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020