5. pyg latin Check yourself some more


#1



https://www.codecademy.com/courses/python-beginner-2W5v7/0/5?curriculum_id=4f89dab3d788890003000096#


When i type in a word with non alphabetical characters, it still prints it. The original.isalpha(): is meant to stop it from doing that. I'm not too sure what i'm doing wrong here.


print 'Welcome to the Pig Latin Translator!'


original = raw_input('Enter a word:')
print original


if len(original) > 0 and original.isalpha():
    print original
else:
    print "empty"


#2

Change those lines to:

original = ""

And see if it works.


#3

You mean like this?

original = raw_input("Enter a word:")
print original


#4

Your answer has taken me to the next exercise but the code isn't working the way it's supposed to. Thanks for your help btw


#5

At the end, you have:

original = ""

if len(original) > 0 and original.isalpha():
    print "You typed a word"
    
else:
    print "empty"

Then it prints the else condition.

Okay, good it did. I just made an assumption from the else print statement.


#6

Oh yes. That works, Thank you!!!


#7

You're welcome.

Have fun coding! :slight_smile:


#8

Sorry you know what, it doesn't actually solve the problem i was having. It worked for no value and a value with numbers but didn't work for an alphabetical phrase, which it is supposed to identify and print. lol so much trouble!

print 'Welcome to the Pig Latin Translator!'

original = raw_input('Enter a word:')
print original

if len(original) > 0 and original.isalpha():
print original
else:
print "empty"


#9

Using the code I suggested or yours?


#10

Yeah, using the code you suggested. everything works but not the .isalpha():
If i type in numbers they still get printed.


#11

pyg = 'ay'

original = raw_input('Enter a word:')

if len(original) > 0 and original.isalpha():
word = original.lower() #Changes the original word to lower case
first = word[0] #selects the forst letter of word
new_word = word + first + pyg #takes the original word selects the first
#letter and adds the ay
new_word = new_word[1:len(new_word)] #this slices the word from the first #letter to the end
print new_word

else:
print 'empty'

Got there in the end


#12

I don't get. My code doesn't allow users to make input.

It's more like predefined.

Am I not getting you? :slight_smile:


#13

You mean your code? i don't understand what you mean.


#14

Never mind as long as you understood what you did. :slight_smile:


#15

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.