Python : 2. : Please print the phrase "Pig Latin"


#1

Block of code

print "Welcome to the Pig Latin Translator!"
name = raw_input("What's your name?")
print "Welcome " + name +","

original = raw_input("Please type a word:")

if len(original) > 0 and original.isalpha():
word = original.lower()
new_word = word + " Latin" + change_word
new_word = new_word[1:len(new_word)]
print new_word
else:
print "No input? Try again!"

I like to know two things:
How this block of code is taking the first letter of mi word?
is making the raw imput all lower case, can i choose to make the first letter .upper and the rest .lower?

Thnk's

Aprecite the help,


#2

Well you can do this,

def pig_latin(word):
    return word[1].upper() + word[2:].lower() + word[0].lower() + ('ay' if word[0].lower() not in 'aeiou' else 'way')

Also, they don't really get into it but if the word starts with a vowel you are supposed to add way to the end, and add ay when it's a consonant.

To get it to work for the course just take off the last part and put ay

def pig_latin(word):
    return word[1].upper() + word[2:].lower() + word[0].lower() + 'ay'

#3

You are doing things in the wrong order
the else/if statement AND ONLY the else/if statement goes alone example:(you can put the whats your name thing if you want it doesn't matter)

print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word")
empty_string = ""
if len(original) < 0:
print "empty"
elif original.isalpha():
print original
else:
print "empty"

hope this helps! (and is the right lesson(its the pop quiz lesson))
-inesines


#4

i get the operational purpouse of the code you guys aid this time and really apreciate.
Looking at the existing code that i have plus making the changes that you guys advice i still dont get how to get the Pig Latin phase to be print after putting the raw imput.

help here!


#5

Are you suggesting to place this code right after: (?)

original = raw_input("Please type a word:")

I see that this codes induces to operate with a class pig_latin


#6

After a lot of work i end up using this code:

change_word = ' Latin'

original = raw_input("Please type the word:")

if len(original) > 0 and original.isalpha():
word = original[0].upper() + original[1].lower() + original[2].lower()
first = word[0]
new_word = first + word + change_word
new_word = new_word[1:len(new_word)]
print new_word
else:
print 'No input? Try again!'

note:

The main target to fix this issue and successfully get the right print output was to focus the attention on: new_word = first + word + change_word


#7

simplest code:is says to print phrase "pig lain " and not to use any logic.

print "Pig latin"