5. Check Yourself... Some More


#1



5. Check Yourself... Some More


This is my code so far:

print 'Welcome to the Pig Latin Translator!'

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

if len(original)>0 and original.isalpha():
    print "original"
elif len(original)<=0 and original.isalpha() is False:
    print "Please try again using only letters and not numbers or special characters!"
else:
    print "Please type something in!"

So basically, I've been trying to test all 3 conditionals to check whether the code works out properly. I've searched these forums in the hopes of an answer but I can't really find one.The issue with this code is that, despite typing in "Hello", it skips straight to the else conditional. There isn't an error message that pops up, the code just doesn't do what I want it to do.


I expected it to follow the print "original" command as I typed in "Hello".


#2

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

I'm not sure what the first line is for, but the second line shouldn't have the raw_input() encased in quotations - you've basically assigned original to the following string: "raw_input(Enter a word:)"

Your elif statement should use or instead of and, otherwise it will only catch cases that are both less than or equal to zero AND not alphabet characters.


#3

Remove this line,

Also you don't need the " " around this statement,

And here, original shouldn't be a string so remove the quotes around it,


#4

Don't need the whole elif statement


#5


#6

why is this not working pls help what should i write in the else statement


#7

rint 'Welcome to the Pig Latin Translator!'

Start coding here!

original = raw_input("Enter a word:")
if len(original) < 0:
(Tab) print(len(original))
else:
(Tab)print "empty"

Just hit enter when ask "Enter a word"


#8

Hey could you explain why you have to use print(len(original)) rather than just using print "Original."? Wasnt working for the longest time and your suggestion helped me out. Thanks!!! :slight_smile: