Check yourself


#1



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


File "python", line 4
if len(empty_string) > 0: and original.isalpha():
^
SyntaxError: invalid syntax


What have i done wrong?


Replace this line with your code. 
print 'Welcome to the Pig Latin Translator!'
original = raw_input("Enter a word")
empty_string = ""
if len(empty_string) > 0: and original.isalpha():
    print (original)
    
else:
    print ("empty")


#2

you are trying to check for characters in the original variable not the empty string one len(empty_string) and to check for that you would change only the value in len() to,

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


#3

I get an error message when i changed it to if len(empty_string) > 0: and original.isalpha():
Oops! Did you accidentally delete the variable named original?


#4

Your code should look like this now,

print 'Welcome to the Pig Latin Translator!'
original = raw_input("Enter a word")
empty_string = " "
if len(original) > 0: and original.isalpha():
    print (original)
    
else:
    print ("empty")

#5

It does look like that but i'm still getting a syntax error


#6

Lol wait there's a colon after this,'

that shouldn't be there your if statement should have only one colon at the end,

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


#7

thanks you it works now :smile:


#8

Help, What is wrong? Syntax error

code:

print 'Welcome to the Pig Latin Translator!'
original = raw_input ("Enter a word:")
empty_string = ""
if len(empty_string) > 0:
print original
else len(empty_string) <= 0:
print "empty"


#9

Your if condition should check original not empty_string,

if len(original) > 0:

and an else statement cannot take a condition directly like that so you would only write,

else:
    print "empty"

#10

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