Python 5/11


#1

hi
in python pyg latin
I put
print 'Welcome to the Pig Latin Translator!'

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

yet when i put 99 it prints 99.


#2

I think you mismatched the logic here. I think it always do else - prints original.

Your code check if given value is a string and if it is shorter than zero characters. This never happens. If it is string it cannot be zero characters. And if it has zero characters it is not a string. This is excluding printing 'empty'.

My code looks like this and works well:

print 'Welcome to the Pig Latin Translator!'

original = raw_input("Enter word:")# Start coding here!
if len(original) > 0 and original.isalpha():
    print original
else:
    print "empty"

You need to print original only while input is longer than zero characters and is a string. In any other case you want it to do 'else'.


#3

My code looks similar to Sial's and it works! Don't get confused by the get.char() in the hint it's not relevant at the moment.

print 'Welcome to the Pig Latin Translator!'

name = raw_input("Enter a word:")
original = name
if len(original) and original.isalpha():
print original
else:
print "empty"


#4

print 'Welcome to the Pig Latin Translator!'

Start coding here!

raw_input("Enter a word:")

original = raw_input("Enter a word:")

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

else:
print "empty"

That's what I had and it worked fine.


#5

Thank you so much everyone! Your feedback helped! :sunny: :smiley::smile: :violin:


#6

I'm using the foolowing code but the console is giving me an error:

Welcome to the Pig Latin Translator!

Traceback (most recent call last):
File "python", line 3, in
TypeError: 'str' object is not callable

Code starts here:

original = raw_input("Enter a word")

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


#7

try it with elif instead of "len(original) and original.isapha
I hope this is the right program
:sparkles:ineseines


#8

print 'Welcome to the Pig Latin Translator!'

# Start coding here!
raw_input("Enter a word:")
original = raw_input
if len(original) > 0 and original.isalpha():
    print original
else: 
    print "Empty"

Error code generated is:

Enter a word: Test
Traceback (most recent call last):
  File "python", line 6, in <module>
TypeError: object of type 'builtin_function_or_method' has no len()

I don't even know what this is trying to tell me. Line six is "if len(original) > 0 and original.isalpha():"


#9

Try to make it one line so you don't need to write "raw_input" twice.
Maybe keep the second line only by adding the parentheses ("Enter a word:").

Give it a try and let us known how it goes.


#10

how did the code work, it didn't work for me


#11

......the commet ".isalpha()" its not working
when i type something like work123
it always print the original first
......then print "empty"......is it a bug or i just do wrong?


#12

I had my code 100% correct and it kept incorrectly returning numbers when I entered them into the "Word" prompt.

The only way I could fix it was by hitting "reset" over and over, and re-typing the code exactly the same. Eventually it executed correctly.

It makes me question the accuracy of codeacademy as a learning tool. I considered subscribing, but if I'm going to end up bashing my head against a wall later on as things get more complex, I'm worried. I know my code was correct, and this is the second time this has happened.


#13

Thought I was going nuts but this worked, thanks.


#15