PygLatin


#1

Below is my code. What am I doing wrong here? does it want me to enter a work in the quotations?

print 'Welcome to the Pig Latin Translator!'

# Start coding here!
original = raw_input(Enter a word:)
if len(original) > 0 and original.isalpha():
 word = original.lower()
 first = word[0]
 else:
 print empty

#2

The prompt phrase needs to be a string. Without quotes it looks like an identifier.

raw_input("Enter a word: ")

#3

Ok, I forgot the quotation marks, but now it states:
File “python”, line 8
else:
^
SyntaxError: invalid syntax
What is going on with line 8?


#4

Indentation error. Be sure to use four spaces for each level of indentation, and that else is directly in line with if.

print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter a word: ")
if len(original) > 0 and original.isalpha():
    word = original.lower()
    first = word[0]
else:
    print empty

#5

Good to know. Thanks for letting me know about my simple mistake


#6

ok, now its telling me to enter a word. I have tried different ones without any luck


#7

actually it will not let me enter a word. why?


#8

I have same problem :frowning:


#9

Can’t say for sure. It may be platform related. Try a couple of things…

from builtins import input

original = input("Enter a word to translate: ")

It is Python 3 syntax that may not pass, but it might work.

original = "elephant"

The above is direct input, so comment out the raw_input() statement.


#10

tahnks! direct input works fine and in the next step of pig latin I can write a word.


#11

I still cannot get it to work. What is wrong with the code. I tried elephant with no luck as well. See below. I have my quotations and indention correct.

print ‘Welcome to the Pig Latin Translator!’

Start coding here!

original = raw_input(“Enter a word:”)
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
else:
print “empty”


#12

But do you? We cannot tell since you have not formatted your code sample per instructions found in posting guidelines.

Did you try the direct input approach? It seems to have worked for @javaslayer86428.


#13

Yes, and it did work. Thank you


#14

Thanks! Direct input worked for me too. :slight_smile:


#17

Instructions: Use and to add a second condition to your if statement. In addition to your existing check that the string contains characters, you should also use .isalpha() to make sure that it only contains letters.

Don’t forget to keep the colon at the end of the if statement!

Here is what I have. What have I done WRONG?
print ‘Welcome to the Pig Latin Translator!’

Start coding here!

original = raw_input(“Enter a word:”)
if len(original) > 0 and original.isalpha():
word = original.lower()
first = word[0]
print “empty”


#18

Missing else before print "empty".


#19

ok, I added the else:. However, it still does not work


#20

Can you re-post your formatted code so we can check the indentation?


#22

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